View Full Version : Get text of a link

Axel Berle
06-08-2004, 03:02 PM

I would need to obtain via a javascript function the text enclosed by the link. Example:

<a href="javascript:myFunction(this)">this is the text!</a>

Somehow the function "myFunction(..)" should have access to the text "this is the text". Of course, I could pass it directly to the function as a parameter, but I would be greate if that wouldn't be necessary!

Thanks for any ideas!


06-08-2004, 03:06 PM
<a href="http://yourdomain.com/yourpage.html" onclick="return yourFunction(this)">Anchor Text</a>
function yourFunction(anchor)
{ anchorText = anchor.firstChild.nodeValue;
/* more stuff */
return false;