How to add a dynamic tooltip over a hyperlink using a function on JS

106 views Asked by At

I have a link, and I want to display a description in a tooltip when hovering. I've been using setAttribute, but it does not work:

    let link = document.createElement("a");
    link.setAttribute("href", `http://mylink.co/${element.key}`);
    link.setAttribute("target", "_blank");
    link.setAttribute("onmouseover", element.description); // <----- here
    link.innerHTML = element.key + ": " + element.summary;

I know this shouldn't be this complex but I'm not very familiarized with JavaScript.

I also tried adding it as function:

link.onmouseover = function() { element.description) } 
1

There are 1 answers

0
ΑΓΡΙΑ ΠΕΣΤΡΟΦΑ On

that you need is to add this:

link.setAttribute("title", "your description here");