热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

删除其中包含空ul标记的div-Removeadivwithanemptyultaginit

Ihavetoremoveadivwithanemptyultaginit.我必须删除一个带有空ul标签的div。EDIT:Theultagisnotempt

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是'menu'。

Example:

before:

after:

提前致谢!

Stijn

2 个解决方案

#1


2  

I'm not sure if I get the idea but this could do the trick

我不确定我是否明白这个想法,但这可以解决问题

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

#2


7  

Try this:

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

推荐阅读
author-avatar
go800li
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有