In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how jquery removes classes". The editor shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "how to clear classes in jquery" can help you solve the problem.
Three methods: 1, use the "element object .removeClass (" class name ")" to delete the specified class, if there is no specified parameter, you can empty the class; 2, use the "element object .toggleClass (" class name ", false)" to delete the specified class; 3, use the "element object .attr (" class ",") "to clear the class.
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
Two methods of clearing classes by jquery
Delete a class using removeClass ()
Delete a class using toggleClass ()
Use attr () and prop () to set the value of the class property to null
1. Delete the class using 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: from all
Element removes the "intro" class
$(document) .ready (function () {$("button") .click (function () {$("p"). RemoveClass ("intro");}) .intro {font-size: 120%; color: red;} this is a title and this is a paragraph.
This is another paragraph.
Remove the "intro" class of all P elements
2. Delete the class using toggleClass ()
The toggleClass () method toggles one or more classes that add and remove selected elements.
This method checks the class specified in each element. Add a class if it does not exist and delete it if it is set. This is called switching effect.
$(selector) .toggleClass (class,switch)
However, by using the "switch" parameter, you can specify that only classes are deleted or added.
Switch: an optional parameter, a Boolean value, that specifies whether to just add (true) or remove (false) classes.
$(document) .ready (function () {$("button") .click (function () {$("p"). ToggleClass ("main", false);}) .main {font-size: 120%; color: red Delete the "main" class of the P element. This is a paragraph.
This is another paragraph.
3. Set the value of the class property to null using attr () and prop ()
Both attr () and prop () can set specified properties and values, and delete the class by setting the value of the class property to null.
$(document) .ready (function () {$("button") .click (function () {$("p") .attr ("class", "); / / $(" p ") .prop (" class ",");})
This is the end of the introduction to "how jquery clears classes". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.