Is there a way with jQuery to remove all the LIs inside a UL with an id of 'myList'?
+9
A:
The following will do the trick:
$('#myList li').remove();
But you should familiarize yourself with jQuery's supported selectors and manipulation
DEfusion
2009-12-06 00:43:24
+6
A:
Slightly simpler approach:
$("#myList").empty();
See empty()
. The other answer works fine for this but gets more awkward for other elements that can have different child elements (eg tables).
cletus
2009-12-06 02:06:27
+1 for I think an answer that would actually run faster vs. finding 'li' children (and the accepted query would find nested li's as well) then removing them.
Doug Neiner
2009-12-06 02:09:22