简体   繁体   English

删除其中带有空ul标签的div

[英]Remove a div with an empty ul tag in it

I have to remove a div with an empty ul tag in it. 我必须删除带有空ul标签的div。

EDIT : The ul tag is not empty, it has a bunch of whitespace in it. 编辑 :ul标签不是空的,它里面有一堆空格。

I want to do this with jQuery 我想用jQuery做到这一点

This is what I have so far: 这是我到目前为止的内容:

$('trim(#menu):empty').parent().remove();

Where the id of my div is 'menu'. 我的div的ID是“菜单”。

Example: 例:

before: 之前:

<div id="container>
    <div id="menu">
      <ul>          


      </ul>
    </div>
</div>

after: 后:

<div id="container>
</div>

Thanks in advance! 提前致谢!

Stijn 斯蒂金

Try this: 尝试这个:

if($("#menu ul:not:has(li)")) {
    $("#menu").parent().remove();
}

I'm not sure if I get the idea but this could do the trick 我不确定我是否知道这个主意,但这可以解决问题

if ($('#menu li').length == 0) {
   $('#menu').remove();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM