簡體   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