Forum Moderators: open

Message Too Old, No Replies

this.href anchor

         

askeli

4:05 pm on Jan 25, 2007 (gmt 0)

10+ Year Member



Just a quick one, in an onclick i can use this.href to grab the url but is there a way to capture the links anchor text too?

Thanks

birdbrain

8:43 pm on Jan 25, 2007 (gmt 0)



Hi there askeli,

does this help...


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">
window.onload=function(){
document.getElementById('mylink').onclick=function() {
alert('href="'+this.href+'" and the anchor text is...\n\n'+this.firstChild.nodeValue);
}
}
</script>

</head>
<body>

<div>
<a id="mylink" href="http://www.webmasterworld.com/">go to webmasterworld</a>
</div>

</body>
</html>

birdbrain

askeli

1:20 am on Jan 26, 2007 (gmt 0)

10+ Year Member



document.getElementById , just what i needed

Many Thanks

birdbrain

4:29 am on Jan 26, 2007 (gmt 0)



No problem, you're welcome. ;)