0
我是新來的jquery和通過官方文檔學習。在閱讀我有類似這樣的HTML代碼...jQuery ul,嵌套列表過濾
<ul class="level-2">
<li class="item-a">A</li>
<li class="item-b">B
<ul class="level-3">
<li class="item-1">1</li>
<li class="item-2">2</li>
</ul>
</li>
<li class="item-c">C</li>
</ul>
我想設置的backgroundColor /邊框屬於「ul.level-2」 ......除了孩子的直接孩子誰嵌套了「UL 「......我成功收購它通過...
$("ul.level-2").children("li").each(function(){
var theChild = $(this).children("ul").length;
if(!theChild){
$(this).css("backgroundColor", "red");
};
});
現在的問題是,jQuery是短代碼的編寫...我如何使用jQuery選擇/過濾器,以短的代碼...在此先感謝...