Change An Element's Class With 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.

Change An Element's Class With JavaScript, Add An Element's Class With JavaScript, Add Additional Class To An Element With JavaScript, Add Class To An Element With JavaScript, Remove Class To An Element With JavaScript, Change Class To An Element With JavaScript, Style To An Element With JavaScript, HTML, JavaScript, PHP, Asp.Net

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')