开发者

jQuery: how to delete list items from lists?

开发者 https://www.devze.com 2022-12-13 04:00 出处:网络
Is 开发者_如何学Cthere a way with jQuery to remove all the LIs inside a UL with an id of \'myList\'?The following will do the trick:

Is 开发者_如何学Cthere a way with jQuery to remove all the LIs inside a UL with an id of 'myList'?


The following will do the trick:

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

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消