Home >Web Front-end >JS Tutorial >How to determine whether the specified class exists in jquery
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.
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"); }
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!