繁体   English   中英

使用jQuery检查类是否存在

[英]Using jQuery to check if a class exist

有没有办法查看某个图层是否具有具有特定类的子图层。

所以在我的html中

html

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

JS / JQ

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

基本上,我想检查我的选项卡是否已经加载了动态html内容。

使用find测试长度

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

或使用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