SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Cha, Cha, Cha!!! Gamermk's Avatar
    Join Date
    Aug 2005
    Posts
    604
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing Classes

    Is there anyway for me to change classes and have it work in Internet Explorer? Currently it only works in Firefox.

    Code:
    document.getElementById(name).className="current";
    The above code is what I'm using right now.
    People don't read ads. They read what interests them,
    and sometimes that happens to be an ad.
    TrulyBored.com | TankingTips.com

  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)
    That should work in IE. You would only have problems if you used setAttribute().
    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
    do righteous deeds
    Join Date
    Aug 2006
    Location
    Türkiye Turkey تركيى
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    These are working on Internet Explorer 7, Firefox and Opera.
    Code:
      
    <script type="text/javascript">
    
    function change () {
    
    var el = document.getElementById('div1');
    el.className ="two";
    
    }
    </script>
    
    <style type="text/css">
    .one { color: red;}
    .two { color: blue; }
    </style>
    
    <button onclick="change ()"> change className </button>
    
    <div class="one" id="div1"> colored text </div>
    Code:
     
    <script type="text/javascript">
    
    function change () {
    
    var el = document.getElementById('div1');
    if(navigator.appName == "Microsoft Internet Explorer" )
    {
    el.setAttribute("className","two"); // for Internet Explorer
    }
    else {
    el.setAttribute("class","two"); // for Opera, Firefox
    }
    }
    </script>
    
    <style type="text/css">
    .one { color: red;}
    .two { color: blue; }
    </style>
    
    <button onclick="change ()"> change className </button>
    
    <div class="one" id="div1"> colored text </div>
    Last edited by muazzez; Feb 27, 2007 at 05:52.
    The Time Through Ages
    1. By the Time, 2. Verily Man is in loss, 3. Except such as have Faith, and do righteous deeds, and (join together) in the mutual enjoining of Truth, and of Patience and Constancy.

  4. #4
    Cha, Cha, Cha!!! Gamermk's Avatar
    Join Date
    Aug 2005
    Posts
    604
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kravvitz View Post
    That should work in IE. You would only have problems if you used setAttribute().
    That's what I thought too. I guess I must be having an issue with case sensitivity.

    @muazzez: I should have clarified better. I am interested in a solution that works in IE6 and IE5 if possible.
    People don't read ads. They read what interests them,
    and sometimes that happens to be an ad.
    TrulyBored.com | TankingTips.com

  5. #5
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gamermk, if you showed us more of your code, we might be able to find the problem for you.
    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
  •