In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what is the use of the hasClass () method, I hope you will gain something after reading this article, let's discuss it together!
.hasClass (className)
Description: determines whether any matching element has a given (style) class assigned.
ClassName
Type: String
The name of the style to query.
The element may have a style name of. In HTML, use spaces to separate multiple styles:
If there is a specified style on the matching element, the .hasClass () method returns true, even though there may be other styles on the element. For example, adding the following code to the HTML above returns true:
$('# mydiv'). HasClass ('foo')
You can also:
$('# mydiv'). HasClass ('bar')
However, this returns false:
$('# mydiv'). HasClass ('quux')
Example:
Look for the 'selected' style on the matching elements.
P {margin: 8px; font-size:16px;}
.selected {color:red;}
This paragraph is black and is the first paragraph.
This paragraph is red and is the second paragraph.
First paragraph has selected class:
Second paragraph has selected class:
At least one paragraph has selected class:
$("div#result1") .append ($("p:first") .hasClass ("selected") .toString ()
$("div#result2") .append ($("p:last") .hasClass ("selected") .toString ()
("div#result3") .append ($("p") .hasClass ("selected") .toString ()
After reading this article, I believe you have a certain understanding of "what is the use of hasClass () method". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.