[thelist] Trouble setting onClick dynamically in IE and FireFox
Chris Dorer
cdorer at gmail.com
Wed Apr 12 23:43:24 CDT 2006
I'm trying to set all my links with an onclick dynamically using body
onload.
When I write out the onclick of the 'a' tag, it'll print me what I set
it to. However, the code WILL not execute the jscript popup. Does
anybody have ANY ideas why this happens and how to make it work properly?
<script type="text/javascript">
function starter() {
var e = document.getElementsByTagName("a");
alert( e.length );
for( var i=0; i < e.length; i++ ) {
e[i].onclick = "alert( 'Hey you!' ); return false;";
alert( e[i].onclick );
}
return true;
}
</script>
<body onload="starter();">
<a id="a" href="page2.php" >Click here and you'll go crazy/a><br />
<a id="b" href="link1.html" >Click here and you won't</a>
</body>
I've been searching all over google not finding an answer. I'm
wondering if anybody came across this issue before.
Thanks in advance,
Chris
More information about the thelist
mailing list