Ian Vink
Ian Vink

Reputation: 68740

jQuery: how to delete list items from lists?

Is there a way with jQuery to remove all the LIs inside a UL with an id of 'myList'?

Upvotes: 3

Views: 191

Answers (2)

cletus
cletus

Reputation: 625007

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).

Upvotes: 6

DEfusion
DEfusion

Reputation: 5613

The following will do the trick:

$('#myList li').remove();

But you should familiarize yourself with jQuery's supported selectors and manipulation

Upvotes: 9

Related Questions