In Internet explorer, using Javascript one can’t access the anchor object’s “text” property. The work around for this is to use “innerHTML” property. However this works in all other browsers.
Complete description with code snippet is shown below
HTML DOM Anchor object has a “text” property that gives the text between opening and closing anchor tags for ex.
<a href=”http://www.google.com/” id=”lnkId” > Show Google </a>
This property words well in all browsers except IE. On IE you get a Java Script error “undefined” on accessing this property.
The solution to this is shown in code snippet below. This script will look for an anchor with id “lnkId” and will show an alert window with the Text between the opening and closing tags
<script language=”javascript” type=”text/javascript”>
var anchorObj = document.getElementById(“lnkId”);
// For all browsers except IE
alert(anchorObj.text);
// For IE
alert(anchorObj.innerHTML);
</script>
Comments (3)
Anonymoussays:
October 7, 2011 at 8:02 pmThanks man!
Anonymoussays:
October 8, 2011 at 4:52 amWelcome @Tennis
Anonymoussays:
December 17, 2012 at 6:15 amThanks a lot