I struggled with this for quite a while. If you’re looking to do the typical:

var newLink = document.createElement("img");
newLink.setAttribute("onclick", "alert('You clicked me')");

You will be upset to discover this works in Firefox and IE 8, but not IE 7 or IE 6. After some Googling I found a nice explanation by Justin French.

The fix:

var newLink = document.createElement("img");
newLink.onclick = function() { alert("You clicked me"); }

Thankfully this works for Firefox and IE 8-6.


No Comments so far



Leave a comment
Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(required)

(required)