英文:
How to add a dynamic tooltip over a hyperlink using a function on JS
问题
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 a function:
link.onmouseover = function() { element.description) }
英文:
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
得分: 1
你只需要添加这部分:
link.setAttribute("title", "在这里添加你的描述");
英文:
that you need is to add this:
link.setAttribute("title", "your description here");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论