Quote:
Originally Posted by skippyV
newbie here. Looking at examples I always see action commands within the anchor tag when javascript :void(0) is involved. e.g.
Code:
<a href="javascript:void(0)" onclick="myJsFunc();">Link</a>
So it's apparent that the javascript gets executed from the 'onclick' action. But I sometimes see the same tag with NO obvious action to take - even though somehow script gets executed. And I don't know how. For example, http://technet.microsoft.com/en-us/s...ive?y=2012&m=2 has links on the right hand side of the page for the years 2012 through 2004. Here is one of those elements:
Code:
<li> <a href="javascript:void(0)"> 2010 </a> </li>
Can someone explain to me how the javascript gets executed when this element (i.e. '2010') is clicked?
|
They are using code similar to this ...
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<style>
</style>
<script type = "text/javascript">
</script>
</head>
<body>
<ul>
<li> <a href="javascript:void(0)"> 2010 </a> </li>
<li> <a href="javascript:void(0)"> 2011 </a> </li>
<li> <a href="javascript:void(0)"> 2012 </a> </li>
</ul>
</body>
<script>
var A = document.getElementsByTagName("UL")[0].getElementsByTagName("A");
for(var i = A.length;i--;){
A[i].onclick = function(){alert(this.innerHTML)};
}
</script>
</html>