Welcome to WebmasterWorld Guest from 3.92.92.168

Forum Moderators: open

Message Too Old, No Replies

this.href anchor

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

Junior Member

10+ Year Member

joined:Nov 29, 2003
posts:94
votes: 0


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

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

Senior Member from GB 

joined:Oct 2, 2003
posts: 1019
votes: 39


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

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

Junior Member

10+ Year Member

joined:Nov 29, 2003
posts: 94
votes: 0


document.getElementById , just what i needed

Many Thanks

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

Senior Member from GB 

joined:Oct 2, 2003
posts: 1019
votes: 39


No problem, you're welcome. ;)