[thelist] Workaround for setAttribute bug in IE7?

Matt Warden mwarden at gmail.com
Thu Dec 14 08:22:57 CST 2006

On 12/14/06, Edwin Martin <edwin at bitstorm.org> wrote:
> > Clearly an operation manipulating the DOM:
> > input.setAttribute('size', 5);
> >
> > Clearly an assignment to an object property:
> > input.size = 5;
> >
> But since all modern browsers bind the properties to the DOM, what is
> the difference?

I'm not really sure how to answer that question. There is no
"difference" in the result. We're talking about a design decision that
does not make it clear that there are magical side effects to
javascript assignment if (1) the property name is one that maps to a
set of possible attribute names and (2) the DOM is representing an
HTML document.

> Here is a list of all bindings:
> http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html

Yes, and you must know this list in order to recognize that this is a
DOM manipulation:

input.size = 5;

and this is not:

input.foo = "bar";

> > Aside from my entire argument, you can do a simple google search to
> > see how often this issue trips up developers.
> >
> I haven't noticed any problems since IE6.

No, not browser bugs. We're discussing the design decision.

This design decision has resulted in a lot of confusion. Why doesn't
label.for work? Oh, namespace clash. Why doesn't div.class work? etc.
Because of this and how browsers work around it, our very own Andrew
Clover suggests to abandon setAttribute/getAttribute altogether:

There would be no issue and no confusion if set/getAttribute were the
only way to manipulate DOM attributes. Attribute names would be
strings and there would be no issue of reserved words. The same issue
exists with modifying the style directly via JS (avoiding the question
of whether anyone should do this). What happens? Libraries pop up
everywhere allowing you to do .setStyle('background-color', 'red');

Matt Warden
Cleveland, OH, USA

This email proudly and graciously contributes to entropy.

More information about the thelist mailing list