我是 bootstrap 和 jQuery 的新手,我目前正在使用 bootstrap 导航栏(多个子菜单)。我有一个 PHP 脚本,可以输出 ul 和 li 元素中的导航。有些 ul 元素中没有 li 元素(某些子菜单没有进一步的子菜单)。因此,没有 li 的 ul,Bootstrap 将其显示为我不想要的空菜单。
无论如何,要查找是否有任何 ul 为空,然后将 CSS 更改为 display: none?我已尝试以下方法但不起作用:
$( "ul" ).each(function() {
if($(this).html()==""){
$(this).css('display','none');
}
});
非常感谢。
最佳答案
关于jquery - 如果 <ul> 元素没有 <li> 元素,如何删除它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17899754/