简体   繁体   English

使用jQuery检查类是否存在

[英]Using jQuery to check if a class exist

Is there a way to see if a layer has a sub layer with a specific class. 有没有办法查看某个图层是否具有具有特定类的子图层。

so in my html i have; 所以在我的html中

html html

<div class='tab'>
   <div class='not-loaded'></div>
</div>

JS/JQ JS / JQ

$('.tab').contains('not-loaded'); //to return a Boolean OR
$('.tab').classExist('not-loaded'); //to return a Boolean

Basicly I want to check if my tabs have already loaded the dynamic html content. 基本上,我想检查我的选项卡是否已经加载了动态html内容。

Test for length using find 使用find测试长度

if($('.tab').find('.not-loaded').length)

Or using has 或使用has

if($('.tab:has(".not-loaded")').length)

您也可以将:first-child与选择器一起使用。

$('.tab :first-child').hasClass('not-loaded');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM