In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "javascript how to judge the existence of class", the content of the explanation is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "javascript how to judge whether class exists" bar!
Methods: 1, use the getAttribute () method to obtain the attribute value of the specified class; 2, use the if statement to determine whether the specified class attribute value is empty, and the syntax is "if (the specified class attribute value = null) {no code;} else {code;}".
The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.
How does javascript determine whether class exists?
You can use the getAttribute () method to get the value of an attribute by name.
Then the if statement is used to determine whether the obtained attribute value is empty.
If empty, the specified class does not exist, if not empty, the specified class exists.
Examples are as follows:
Let _ class = document.getElementsByTagName ('div') [0] .getAttribute (' class'); if (_ class = = null) {console.log ('not class');} else {console.log (_ class) } Thank you for your reading. The above is the content of "how to judge the existence of class by javascript". After the study of this article, I believe you have a deeper understanding of how to judge the existence of class by javascript, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.