javascript toggle class name

Posted on 2010-01-02
Last Modified: 2012-05-08
this is my code for toggle class name

Working in Firefox and IE locally, working in Firefox online, NOT WORKING in IE online!!
How can it be? I have even saved page from internet (that is not working) to local pc again and  is working.

If you don't have quick fix please give me some other toggle class script.
<script type="text/javascript"> 

function changeClass(elementID, className1,className2)


    var elem = document.getElementById(elementID);

    elem.className = (elem.className == className1)?className2:className1;



<a id="check" class="none" href="javascript:{}" onclick="showHide('somediv'); changeClass ('check','active','none')" >test</a>

Open in new window

Question by:mankis
    LVL 82

    Accepted Solution

    <a id="check" class="none" href="#" onclick="showHide('somediv'); changeClass ('check','active','none'); return false;" >test</a>

    Author Comment

    and now is not working locally.

    here is my css, just in case, but It displays without any style so it probably doesn't matter
                        width: 43px;
          height: 55px;
          padding: 0 5px 0 0;
          background: url(../images/unchecked.gif) no-repeat top left;
          display: block;
          float: left;
          background: url(../images/checked.gif) no-repeat top left;

    Author Comment

    it works without return false; at the end. Don't know why
    thanks for helping me

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
    As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
    In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now