2015-07-20 137 views

回答

9

你可以結合:has()/:empty jQuery選擇:

Example Here

$('li:has(a:empty)').remove(); 
+3

^1很好用選擇器組成。在我看來,這裏是正確的選擇。 –

0

僅刪除li元件與空a兒童使用這樣的:

$("li > a:empty").parent().remove(); 
//OR $('li:has(>a:empty)').remove(); 

實例:

<li><a href=''>List item</a></li> <!-- not remove this --> 
<li><a href=''></a></li> <!-- remove this --> 
<li><span><a href=''></a></span></li> <!-- not remove this -->