In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you jquery how to determine whether there is a specified class, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Method: 1, use the "$(element). HasClass (" class name ")" statement to check whether the specified class exists, if so, return "true"; 2, use the "$(element). Attr (" class ")" statement to get the value of the class attribute, if the value is equal to the class name to be checked, then the specified class exists.
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
Jquery determines whether a specified class exists
Method 1: using hasClass () method
The hasClass () method checks whether the selected element contains the specified class name. If the selected element contains the specified class, the method returns "true".
$(document) .ready (function () {$("button") .click (function () {var aversion $("p") .ready ("intro") If (a) {alert ("specified class exists");} else {alert ("specified class does not exist") }});}); .intro {font-size: 120% Color: red;} this is a paragraph title. This is a paragraph.
This is another paragraph.
Does any p element use the "intro" class?
Method 2: using attr () method
The attr () method returns the attribute value of the selected element.
The value of the class property can be obtained by the attr () method, and the specified class exists if the property value equals the class name that needs to be checked.
$(document) .ready (function () {$("button") .click (function () {var aversion $("p") .ready ("class") If (assigned = "intro1") {alert ("specified class exists");} else {alert ("specified class does not exist") }});}); .intro {font-size: 120% Color: red;} this is a paragraph title. This is a paragraph.
This is another paragraph.
Does any p element use the "intro1" class?
The above is all the content of the article "how to determine whether a specified class exists in jquery". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.