Entry
How can I get the text of the clicked link in Morzilla Firefox
Apr 8th, 2008 19:28
ha mo, Dave Clark, Vinay Mathod,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Vinay,
If the inner content of the link is pure text, then the following
will work in any standard browser -- and, yes, that includes IE6:
<a href="javascript:void(0)"
onclick="alert(this.firstChild.data);
return false;">Link Text</a>
Any additional markup, as part of the inner content of the link,
will confuse the issue. For example:
<a href="javascript:void(0)"
onclick="alert(this.firstChild.firstChild.data);
return false;"><b>Link Text</b></a>
Then, in some browsers, even additional newlines can confuse the
issue further. The following works the same as before in IE6:
<a href="javascript:void(0)"
onclick="alert(this.firstChild.firstChild.data);
return false;">
<b>Link Text</b>
</a>
However, in Firefox, the same HTML arrangement would require the
following change to the JavaScript:
<a href="javascript:void(0)"
onclick="alert(this.childNodes[1].firstChild.data);
return false;">
<b>Link Text</b>
</a>
Take care,
Dave Clark
www.DaveClarkConsulting.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com