Add or Remove Class to Element using Javascript

by Sasikumar 2014-07-08 14:18:02

We can use the following method to add class to element in javascript:
Add Class using Javascript :
var id = 'my_id';
var my_class_name = " your_class_name";
var d;
d = document.getElementById(my_id);
d.className = d.className.replace(my_class_name,""); 
d.className = d.className + my_class_name;
We can use the following method to remove class from element in javascript:
Remove Class using Javascript:
var id = 'my_id';
var my_class_name = " your_class_name";
var d;
d = document.getElementById(my_id);
d.className = d.className.replace(my_class_name,"");
1489
like
0
dislike
0
mail
flag

You must LOGIN to add comments