简体   繁体   English

如何使用jQuery删除UL内部的HTML元素?

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

I have the following HTML code: 我有以下HTML代码:

<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? 有没有一种简单的方法可以使用jQuery从ul完全删除li元素?

There a method just for that, empty() 为此,有一个方法empty()

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

Description: Remove all child nodes of the set of matched elements from the DOM. 说明:从DOM中删除匹配元素集的所有子节点。

No need for "tricks". 无需“技巧”。

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

这将删除所有li元素

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用jquery或javascript计算类相同的html元素,但在特定的内部<ul> - How do I count html elements whose class is the same using jquery or javascript, but inside a particular <ul> 如何使用 jquery 在 ul 中删除动态添加的 li - how can I remove dynamically added li in ul using jquery 我如何使用 jQuery 删除除特定 class 之外的所有 div 和其他 DOM HTML 元素 - How can i remove all div's and other DOM HTML elements except a particular class using jQuery 如何在ul元素中使用jQuery .html()函数? - How to use jQuery .html() function with ul elements? 如何使用jQuery / javascript在HTML ul可排序列表中获取子项的索引? - How can I get the indices of children in a HTML ul sortable list, using jQuery/javascript? 如何使用JQuery删除iframe中的元素? - How can I remove elements in an iframe using JQuery? 如何重命名 <li> 里面 <ul> 使用jQuery吗? - How do I rename an <li> inside a <ul> using jQuery? 如何使用 jQuery 通过键删除 JSON 中的 JSON? - How can I remove a JSON inside a JSON by a key using jQuery? 如何在第n个元素后删除元素并追加新元素 <li> 在一个 <ul> 清单? - How can I remove elements and append new elements after the nth <li> in a <ul> list? 如何使用 Jquery 将 HTML 元素移到其容器之外? - How can i move HTML elements outside their containers using Jquery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM