检查子元素,如果存在子代,隐藏父代 [英] check for child element, hide parent if child exists
本文介绍了检查子元素,如果存在子代,隐藏父代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试过这个:
<script>
$(document).ready(function() {
$('#title_article:not(:has(>hr:first-child))').hide();
});
</script>
但从不显示..
But never shows..
<div id="title_article">
<span style="padding-left:121px;">Article | </span>
<span class="entry-date"><?php echo get_the_date(); ?></span>
</div>
要检查< hr> $ c的子元素$ c>如果
< hr>
存在hide parent或 #title_article
Seeking to check for child element of <hr>
if <hr>
exists hide parent or #title_article
< hr>
不会在< div id =title_article>< / div>
但以下:
<!-- page content -->
<div id="title_article></div>
<hr>
<!-- page content -->
推荐答案
您正在查找。next()
Get the immediately following sibling of each element in the set of matched elements. If a selector is provided, it retrieves the next sibling only if it matches that selector.
You have to do something like:
if ($('#title_article').next('hr').length)
$('#title_article').hide();
< hr>
不是 #title_article
的子元素,而是兄弟。
In your example, <hr>
is not a child element of #title_article
, but a sibling.
这篇关于检查子元素,如果存在子代,隐藏父代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文