How does javascript determine whether class exists?
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!