Home > Back-end >  can span tag redirect to a link
can span tag redirect to a link

Time:10-21

created a code where javascript randomly selects a span tag and highlights that tag. My question is, after that tag is selected is there a way, I can redirect it to a another website link? If yes, can you direct me please?

CodePudding user response:

No span done work as a link. you can add a funtion to span to redirect to the link

<span id='span123' onclick="openlink(this)">This Span is 123</span>

function openlink(span){
var id = span.attributes['id']
window.open("https://www.google.com?q=" id); 
}

CodePudding user response:

Here is a solution using an event handler. Since you've already made the random select function in JavaScript you can integrate this easily.

highlightedTag.onclick = () => {
    window.open("https://www.google.com");
}
  • Related