views:

102

answers:

2

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
+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
+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