The removeClass() method removes one or more class names from the selected elements. Note: If no parameter is specified, this method will remove ALL class names from the selected elements.
To remove all CSS classes of an element, we use removeClass() method. The removeClass() method is used to remove one or more class names from the selected element.
The syntax for Removing CSS classes to an element: removeClass(class_name);
getElementsByClassName() The getElementsByClassName method of Document interface returns an array-like object of all child elements which have all of the given class name(s).
Do not access className
from the style
object, access it directly like
this.className
document.querySelector('button').onclick = function() {
this.className = '';
}
.myClass {
color:red;
}
.second {
color:green;
}
<button id="button" class="myClass second">click me</button>
HTML DOM removeAttribute()
Method:
document.querySelector('button').onclick = function() {
this.removeAttribute("class");
}
.myClass {
background-color:red;
}
.second {
box-shadow: 0px 0px 10px 10px;
}
<button id="button" class="myClass second">click me</button>
Use this.classname
instead of this.style.className
. Your Javascript code will be like this:
document.querySelector('button').onclick = function() {
this.className = ''; //remove the .style
}
Fiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With