Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
97
rated 0 times [  102] [ 5]  / answers: 1 / hits: 81449  / 14 Years ago, wed, march 2, 2011, 12:00:00

I am using JavaScript and I want to add/remove a Class attribute if a button is clicked. I am able to add the class, but I don't know how to remove it. how can I do that?



window.onload = function(){
var buttonGo = document.getElementsByTagName('button')[0];
var buttonCom = document.getElementsByTagName('button')[1];
var box = document.getElementById('box');
buttonGo.onclick = function(){
box.setAttribute('class','move');
}
buttonCom.onclick = function(){
// how to remove class name?
}
}

More From » javascript

 Answers
46

box.removeAttribute(class) should work.


[#93498] Tuesday, March 1, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jamaal

Total Points: 515
Total Questions: 102
Total Answers: 107

Location: France
Member since Thu, May 6, 2021
3 Years ago
;