onclick event not working, instead it triggering while page load
In the following code I simply want the number of matched element by tag
name, But it returns 0 and it alerts while page load (not on click as I
want). Cannot find any mistake over an hour
<!DOCTYPE HTML>
<HTML>
<head>
<script language="javascript">
document.getElementById("all").onclick = alert(
document.getElementsByTagName("a").length);
</script>
</head>
<body>
<div id="all" class="a">Click</div>
<div class="a"></div>
<div class="a"></div>
</body>
</HTML>
I'm a total newbie in JavaScript
No comments:
Post a Comment