Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2004
    Location
    Minnesota
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer setAttribute in IE?

    Ok, I have a tabbed menu that has a different class on the tab that is active.

    here is the html:
    Code:
    <div id="menu">
    	<ul id="navtabs">
            <li id="yourcar" class="activelink"><a href="javascript:sndReq('yourcar')">Car</a></li>
            <li id="wheels"><a href="javascript:sndReq('wheels')">Wheels</a></li>
            <li id="tires"><a href="javascript:sndReq('tires')">Tires</a></li>
            <li id="paint"><a href="javascript:sndReq('paint')">Paint</a></li>
    	</ul>
    </div>
    So as you can see from the above, 4 tabs - each with a id. The active tab has the class="activelink" attached to the <li>.

    here is the JS function sndReq()::
    Code:
    function sndReq(action) {
    
    //strip all classes
    		document.getElementById("yourcar").removeAttribute("class");
    		document.getElementById("tires").removeAttribute("class");
    		document.getElementById("wheels").removeAttribute("class");
    		document.getElementById("paint").removeAttribute("class");
    //set class on clicked item
    		document.getElementById(action).setAttribute("class","activelink");
    
    }//END sndReq
    It works great in Firefox, but IE no likey. Is there a way around this?

    Thnks for any tips!
    Last edited by pixelEngine; 06-05-2006 at 11:17 PM.
    “That rug really tied the room together. ”

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,511
    Thanks
    3
    Thanked 504 Times in 491 Posts
    document.getElementById("yourcar").className='whatever';

    document.getElementById("yourcar").className='';
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    setting attributes is tricky in DOM 1+ . Moz uses setAttribute('class'), while IE uses setAttribute('className'), so that the old DOM 0 solution, as vwphillips has recomanded is the best cross browser.

    element.className

    Thre are also tricky attributes, such as the compunded HTML which, for IE, must be in camel case

    setAttribute('colSpan')

    In other special cases, such as readOnly, the Boolean false woun't work, so that the a good way to switch the value is to remove it removeAttribute()

    Well, to get an attribute value is simplier with XML/XHTML DOM method

    element.getAttributeNode('attribute').nodeValue

    which works ok even in HTML 4
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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