How does jquery remove a class
This article focuses on "how jquery removes a class". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how jquery removes a class.
Removal method: 1, use removeClass () to remove the specified class from the selected element, syntax "element object .removeClass (class name)"; 2, use removeAttr () to remove class attributes from the element, syntax "element object .removeAttr (" class ")".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
Jquery removes a class
Method 1: use removeClass ()
The removeClass () method removes one or more classes from the selected element.
$(selector) .removeClass (class)
Note: if no parameters are specified, the method removes all classes from the selected element.
Example:
$(document) .ready (function () {$("button") .click (function () {$("p:first"). RemoveClass ("intro");}) .intro {font-size: 120%; color: red } this is a paragraph title. This is a paragraph.
This is another paragraph.
Remove the "intro" class of p element
Method 2: use removeAttr ()
The removeAttr () method removes attributes from the selected element.
Simply use this method to remove the class attribute from the selected element to remove the class
$(selector) .removeAttr ("class")
Example:
$(document) .ready (function () {$("button") .click (function () {$("p:first"). RemoveAttr ("class");}) .intro {font-size: 120%; color: red } this is a paragraph title. This is a paragraph.
This is another paragraph.
Remove the class of the p element
At this point, I believe you have a deeper understanding of "how jquery removes a certain class". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!