View Full Version : setAttribute() and IE6

12-10-2010, 05:49 PM
Having some issues with setAttribute() and IE6, works in other browsers just being illusive in IE6.

Any help here would be great. :)

Currently using IETester v0.4.6.


<div id="Element">Element</div>

document.getElementById("Element").setAttribute('onclick', 'alert("!")');

Logic Ali
12-10-2010, 06:30 PM
Never use setAttribute when direct assignment will work:

document.getElementById("Element").onclick = function(){ alert("!"); };

12-10-2010, 08:27 PM
Thanks for that tip :)

12-11-2010, 11:24 AM
PS. Element is the name of a DOM interface object. and because IE writes all IDs and names in the global scope, you can get name collision.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum