<div id="example">
<div id="test"></div>
</div>
<div id="another">Blah</div>
Run Code Online (Sandbox Code Playgroud)
我想设置,$('#another').hide()但只有#example包含一个被调用的子元素#test,这可能吗?好像是这样.
elc*_*nrs 68
使用 length
if ($('#example').find('#test').length) {
// found!
}
Run Code Online (Sandbox Code Playgroud)
我认为您正在寻找的是以下内容
if (jQuery.contains($('#example'), $('#test')) {
$('#another').hide();
}
Run Code Online (Sandbox Code Playgroud)
这可能也有效,但不能确定.
if ($('#test', $('#example')).size() > 0) {
$('#another').hide();
}
Run Code Online (Sandbox Code Playgroud)
jQuery 手册建议使用:
if ($('#parent').has('#child').length) {
//do something
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
52785 次 |
| 最近记录: |