Forum Moderators: open

Message Too Old, No Replies

setAttribute problem

         

orion_rus

7:09 pm on Oct 15, 2004 (gmt 0)

10+ Year Member



Hello, setAttribute nicely work in Mozilla, but when i try to attach event in IE, it tells error, how i can make it works in both browsers?

dcrombie

10:21 am on Oct 18, 2004 (gmt 0)



I use something like the following - it seems to be cross-browser compatible. Other sites use the MSIE code by default and ignore get/setProperty.

if(node.currentStyle) { 
// applies to msie only
node.style.property = newValue;
} else {
node.style.setProperty("property", newValue, "");
}

Edit: OK, you wanted setAttribute instead of setProperty. The solution should be similar...

Bernard Marx

7:52 am on Oct 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



setAttribute doesn't work in IE for setting event handlers.
Use:

elementRef.onclick = functionRef

or use the newer methods:

elementRef.attachEvent(..) // IE
elementRef.addEventListener(..) // Standards