[thelist] removeAttribute('class') not working in IE

Andrew Clover and-evolt at doxdesk.com
Tue Sep 20 16:26:12 CDT 2005


Iain wrote <iain at firelightning.com>:

> currentImage.removeAttribute('class');

> Viewing the generated source from IE reveals that both the new
> division and the nested image both have the class attribute.

This is a consequence of IE's hopeless hacked-together implementation of 
DOM Level 1 Core. IE in its wisdom translates getAttribute, setAttribute 
and removeAttribute into access to normal object.member access. This means:

   a. you can do stupid things like getAttribute('parentNode'), and
      are disallowed from setting custom attributes that happen to have
      the same name as a non-attribute member (especially annoying as
      it may break your scripts when IE grows new member functions)

   b. it doesn't work when you use attributes that have a different
      name as a property, like class/className and for/htmlFor. You
      can do:

      currentImage.removeAttribute('class');
      currentImage.removeAttribute('className');

      to makes sure that both IE and compliant browsers see the change,
      but it's probably easier just to use the member access
      (currentImage.className) instead as this works consistently.

-- 
And Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/


More information about the thelist mailing list