How to change the css class name of the html element through JavaScript?

Poster
Posted by Poster under JavaScript category on | Views : 6579
To change the css class name of the html element through JavaScript, use the following function

//Change the class of the element
function ChangeClass(t, clas)
{
t.className = clas;
}


Use the above function like this
<div class='oldClass' onclick="ChangeClass(this, 'newClass')">Change my class</div>


On click of the above div the class name will be changed to newClass.

Comments or Responses

Login to post response