简体   繁体   中英

How can I remove HTML elements inside a UL using jQuery?

I have the following HTML code:

<ul class="message" id="stats-results">
   <li>DS1 Records: <span id="ds1Count"></span></li>
   <li>DEV Records: <span id="devCount"></span></li>
</ul>

Is there an easy way for me to completely remove the li elements from the ul using jQuery?

There a method just for that, empty()

$('#stats-results').empty();

Description: Remove all child nodes of the set of matched elements from the DOM.

No need for "tricks".

$("#stats-results").html("");

这将删除所有li元素

尝试$('ul.message li').remove();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM