How do I hide a parent div if the child div doesn't contain an tag?

后端 未结 4 1673
梦毁少年i
梦毁少年i 2021-01-27 07:41

I\'m trying to hide a parent div (i.e., #post) if the child div (i.e., .post-title) doesn\'t contain an tag. Any insight in how to accomplish this correct

4条回答
  •  [愿得一人]
    2021-01-27 08:17

    You can simply use jQuery's .filter

    Like so:

    $('.post-title').filter(function(i) { return !$(this).find('a').length }).hide();
    

    See example below

    $('.post-title').filter(function(i) { return !$(this).find('a').length }).hide();
    
    
    Link here
    NO LINK
    NO LINK
    Link here

提交回复
热议问题