Entry
How can I get the text of the clicked link?
Apr 3rd, 2000 09:35
Martin Honnen, Laurent LESTRADE,
With NN3/4:
document.links[linkIndex].text
With IE4+:
document.links[linkIndex].innerText
With NN6 you need to collect the text or just access the first text
node:
document.links[linkIndex].firstChild.nodeValue
Here is an example showing the text in a confirm dialog:
<HTML>
<HEAD>
<SCRIPT>
function getLinkText (link) {
return link.text ? link.text :
link.innerText ? link.innerText :
link.firstChild.nodeType == 3 ? link.firstChild.nodeValue :
'';
}
</SCRIPT>
</HEAD>
<BODY>
<A HREF="http://JavaScript.FAQTs.com"
ONCLICK="var t = getLinkText(this);
return confirm('Goto ' + t);"
>
JavaScript.FAQTs
</A>
|
<A HREF="http://www.kibo.com"
ONCLICK="var t = getLinkText(this);
return confirm('Goto ' + t);"
>
GOD
</A>
</BODY>
</HTML>