我有以下内容:
<div class="main">
<div class="sub"></div>
</div>
<div class="main">
<div class="sub"></div>
</div>
<div class="main">
<div class="another"></div> <!-- Attention: This div does not have .sub -->
</div>
<div class="main">
<div class="sub"></div>
</div>
如何检查有一个不包含 div.sub 的 div.main?
我下面的代码似乎只检查第一个 div.main
if ($('.main .sub')[0]) {
console.log('All div.main contain div.sub');
}
else {
console.log('Some div.main which does not contain div.sub');
}