[thelist] Workaround for setAttribute bug in IE7?

Lee kowalkowski lee.kowalkowski at googlemail.com
Thu Dec 14 10:40:26 CST 2006

On 14/12/06, Matt Warden <mwarden at gmail.com> wrote:
> 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";

Correct.  This is where you can get IE to absolutely rock (well,
almost, let's not get too carried away).

In IE, input.foo = "bar" *is* a DOM manipulation, unless
document.expando == false, in which case IE actually throws an
exception when you try to do input.foo = "bar" *OR*
input.setAttribute("foo", "bar").

This can be really handy for catching typos, but unfortunately,
setAttribute lovers are at a disadvantage because IE then expects the
non-standard setAttribute("className") to set the class attribute.
Infuriating indeed!

If you're stashing all sorts of arbitrary properties into your objects
for your own needs, this would cause problems, but you can still use
it for a section of DOM manipulation you're having trouble with:

  document.expando = false;
  ... // some DOM manipulation that doesn't appear to work
  document.expando = true;

If you get an exception, the penny will finally drop (hopefully).


More information about the thelist mailing list