Home > Web Front-end > JS Tutorial > body text

How to determine whether the specified class exists in jquery

藏色散人
Release: 2020-11-30 14:45:23
Original
1869 people have browsed it

Jquery method to determine whether the specified class exists: first create a code sample file; then pass "if(yz!=-1){"console.log("...");}else{console .log("...");} method can be used to determine whether the specified class exists.

How to determine whether the specified class exists in jquery

The operating environment of this tutorial: Windows 7 system, jquery version 1.10.0. This method is suitable for all brands of computers.

Recommended: "jquery Tutorial"

jQuery determines whether the class of the specified object exists

The code is as follows:

var str = $(obj).attr("class");
var strs = str.split(" ");
var yz = $.inArray("cur",strs);
if(yz!=-1){
    console.log("当前对象含有名字为cur的class");
}else{
    console.log("当前对象不存在名字为cur的class");
}
Copy after login

For more programming-related knowledge, please visit: Programming Learning! !

The above is the detailed content of How to determine whether the specified class exists in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template