Add Or Remove A Class To An Element In JavaScript
> Here we consider how to
Change An Element's Class With JavaScript.
> In JavaScript, we can select an element by using
document.getElementById("Id").
> For Adding a class in JavaScript, we can make use of
className.
> For Removing a class In JavaScript, we can make use of
className.replace.
> Here is an example. Lets consider a div with ID
divID.
> By using className and className.replace, we can Change An Element's Class.
> In Jquery, we can make use of addClass and removeClass for Changing the Class.
> Adding a Class in Jquery can be done as follows.
$('#divID').addClass('ClassName')
> Removing a Class in Jquery can be done as follows.
$('#divID').removeClass('ClassName')
Watch Video of this Content on Video Streaming