D
David Mark
[snip]
It isn't buggy, but broken as designed.
This is the same as using setAttribute in IE, which is the whole
problem with IE's implementation. In this particular case it doesn't
make any difference as the element property is a string and the
attribute name is not a reserved word or camel-case.
On the other hand, these will all fail in IE:
el.setAttribute('disabled', 'disabled'); // disabled property is
boolean
el.setAttribute('style', 'color:red'); // style property is an object
el.setAttribute('onclick', 'alert("test");'); // onclick property
needs a function
el.setAttribute('for', 'myID'); // for is reserved, property is
htmlFor
el.setAttribute('maxlength', '10'); // property is maxLength
The getAttribute method has the same botched design. Of course, it is
rarely useful to call getAttribute to retrieve something that is
exposed by a standard DOM property in the first place.
The feature test for this is trivial, but a full workaround is not as
IE does weird things when setting the type property of input
elements. I got tired of the get/setAttribute taboo a while back and
worked out wrappers, but they are not pretty.
It is beyond belief that MS didn't change this in IE7.
setAttribute is buggy in IE, set the property directly:
It isn't buggy, but broken as designed.
js.type="text/javascript";
This is the same as using setAttribute in IE, which is the whole
problem with IE's implementation. In this particular case it doesn't
make any difference as the element property is a string and the
attribute name is not a reserved word or camel-case.
On the other hand, these will all fail in IE:
el.setAttribute('disabled', 'disabled'); // disabled property is
boolean
el.setAttribute('style', 'color:red'); // style property is an object
el.setAttribute('onclick', 'alert("test");'); // onclick property
needs a function
el.setAttribute('for', 'myID'); // for is reserved, property is
htmlFor
el.setAttribute('maxlength', '10'); // property is maxLength
The getAttribute method has the same botched design. Of course, it is
rarely useful to call getAttribute to retrieve something that is
exposed by a standard DOM property in the first place.
The feature test for this is trivial, but a full workaround is not as
IE does weird things when setting the type property of input
elements. I got tired of the get/setAttribute taboo a while back and
worked out wrappers, but they are not pretty.
It is beyond belief that MS didn't change this in IE7.