SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2003
    Location
    earth
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    setAttribute does not work in IE

    I tried something like this:

    document.getElementById("spanID").setAttribute("class", "testClass");

    Works in Firefox, but does not work in IE (both 6 and 7). Anyone know of any workaround?

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use className instead of setAttribute().
    Code:
    document.getElementById("spanID").className = "testClass";
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2003
    Location
    earth
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot Kravvitz, works perfect.

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    for class to be set with setAttribute in IE you have to use className:

    Code:
    elm.setAttribute('className', 'class');
    the same is for "for" in lable elements

    Code:
    elm.setAttribute('htmlFor', 'for');
    IE problem only
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •