如果子div不包含< a&gt ;,该如何隐藏父div?标签? [英] How do I hide a parent div if the child div doesn't contain an <a> tag?

查看:94
本文介绍了如果子div不包含< a&gt ;,该如何隐藏父div?标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果子div(即.post-title)不包含<a>标记,则我试图隐藏父div(即#post).关于如何使用我修改的代码正确完成此操作的任何见解?

I'm trying to hide a parent div (i.e., #post) if the child div (i.e., .post-title) doesn't contain an <a> tag. Any insight in how to accomplish this correctly with the code I've modified?

<div id="latest">
    <div id="post">
        <div class="post-image post-image-1"></div>
        <div id="post-content">
            <div class="post-title post-title-1"></div>
            <div id="post-date"></div>
        </div>
    </div>
<div id="post">
        <div class="post-image post-image-2"></div>
        <div id="post-content">
            <div class="post-title post-title-2"></div>
            <div id="post-date"></div>
        </div>
    </div>
</div>

$('.post-title').not($('a').hide($("#post"));

推荐答案

首先:不要多次使用ID.每个ID都应该是唯一的:)

Firstly: dont use IDs mulitple times. Every ID should be unique :)

其次:$('.post').not( ':has(".post-title a")' ).addClass('hide')

这篇关于如果子div不包含&lt; a&gt ;,该如何隐藏父div?标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆