如何检测父元素中的任何子元素是否具有特定类? [英] How to detect if any child elements within a parent element has a certain class?
本文介绍了如何检测父元素中的任何子元素是否具有特定类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试检测父图库" div中的任何子div是否具有显示"类.
I'm trying to detect if any of the sub-divs within the parent "gallery" div have a class of "show".
<div id="gallery">
<div class="show"></div>
<div></div>
<div></div>
</div>
if (TEST CONDITION) {
alert('sub element with the class show found');
} else {
alert('not found');
}
它不必为if/else格式.能够以jQuery链式的方式做到这一点会更好.
It doesn't have to be in a if/else format. To be able to do this in a jQuery chainning sort of way would be better.
推荐答案
这应该做到:
if ($("#gallery > div.show").length > 0)
这篇关于如何检测父元素中的任何子元素是否具有特定类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文