My goal is to change the "onclick" attribute of a link. I can do it successfully, but the resulting link doesn't work in ie8. It does work in ff3.
For example, this works in firefox3, but not ie8. Why???
<p><a id="bar" href="#" onclick="temp()">click me</a></p>
<script>
doit = function(){
alert('hello world!');
}
foo = document.getElementById("bar");
foo.setAttribute("onclick","javascript:doit();");
</script>
You could also set onclick to call your function like this:
This way, you can pass arguments too. .....
You don't need to use setAttribute for that - This code works (IE8 also)
You also can use:
your best bet is to use a javascript framework like jquery or prototype, but, failing that, you should use:
edit:
also, your function is a little off. it should be