SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    setAttribute support

    objTarget.setAttribute("class", "tipWrapperSpanOver");

    what type of browser support is there for setAttribute?

    I can't seem to get it to work in IE7...

  2. #2
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure... I think Firefox, Opera and maybe Safari (latest versions) support it but as you say IE lacks support.

    The alternative:

    Code JavaScript:
    objTarget.className = "tipWrapperSpanOver";

    I think http://www.quirksmode.org has a list of supported functions/objects etc.. (In various browsers) but I can't find it...

    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think IE has a very primitive implementation of setAttribute() that basically translates element.setAttribute(attr, value) into element.attr=value. It fails on attribute names that are reserved words in JavaScript (like class and for).

    I believe that setAttribute("className", "tipWrapperSpanOver") will work in IE, but it will probably fail in standards-compliant browsers.
    Birnam wood is come to Dunsinane

  4. #4
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I went with this and it seems to work well...
    objTarget.className = "tipWrapperSpanOver";

  5. #5
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should be adding to, not overriding the className if any previous exists. There are plenty of addClass custom functions on the web.

  6. #6
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree with Tommy.

    Quote Originally Posted by SoulScratch
    You should be adding to, not overriding the className if any previous exists. There are plenty of addClass custom functions on the web.
    You can see an old version of my functions for this here: http://www.sitepoint.com/forums/show...28&postcount=3
    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.


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
  •