Organizational Research By

Surprising Reserch Topic

how to replace div class name using javascript?



asked Sep 13, 2013 in JAVASCRIPT by rajesh
edited Sep 12, 2013
0 votes
26 views



Related Hot Questions

1 Answer

0 votes
You have to define the second class name. Currently, you have got a function which changes the class name to a hard-coded value, independent on the current class name. See also: MDN: if...else
 
function change_autorefreshdiv(){
    var NAME = document.getElementById("first_name");
    var currentClass = NAME.className;
    if (currentClass == "second_name") { // Check the current class name
        NAME.className = "first_name";   // Set other class name
    } else {
        NAME.className = "second_name";  // Otherwise, use `second_name`
    }
}   
 

 

answered Sep 13, 2013 by rajesh
edited Sep 12, 2013

...