[英]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.