检查父元素是否包含使用jQuery的某个子元素 [英] Check if parent element contains certain child element using jQuery
本文介绍了检查父元素是否包含使用jQuery的某个子元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<div id="example">
<div id="test"></div>
</div>
<div id="another">Blah</div>
我想设置 $('#another')。hide()
但只有当 #example
包含一个名为 #test
的子元素时,这可能吗?看起来好像是这样。
I want to set $('#another').hide()
but only if #example
contains a child element called#test
, is this possible? It seems like it would be.
推荐答案
使用长度
if ($('#example').find('#test').length) {
// found!
}
这篇关于检查父元素是否包含使用jQuery的某个子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文