li").not(":eq(0)").remove()]; 2. Use filter to judge, the code is 【$("ul>li").filter(function(index)】."> How to dynamically delete LI using jQuery-JS Tutorial-php.cn

How to dynamically delete LI using jQuery

coldplay.xixi
Release: 2023-01-04 09:37:57
Original
2910 people have browsed it

JQuery's method of dynamically deleting LI: 1. Use not to judge, the code is [$("ul>li").not(":eq(0)").remove()]; 2. Use filter to judge, the code is [$("ul>li").filter(function(index)].

How to dynamically delete LI using jQuery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, DELL G3 computer.

Recommendation:jquery video tutorial

jQuery method to dynamically delete LI:

Sometimes we know the ID of UL, but it is miserable to find the LI to clear it. Here are some methods for reference. Setting the ID of Li is a good method, but do not set it to an ID. When the time comes, Deletion will only delete the first

You can use

$("#ul li").not(":first").remove();
Copy after login

This method can delete all other li that are not the first li.

I use:

$(document).ready(function(){ $("#search_content").keyup(function () { if(CheckChinese($("#search_content").val())) { $.ajax({ type: "POST", anync: true, url: "HelpCenterSuggestion.ashx", cache: false, dataType: "text", data: { m: $("#search_content").val() }, success: function (result) { alert(result); $("#UlContent li").remove(); $("#UlContent").append(result); } }); } });
Copy after login

There are many methods, you can also use:

1, use not

$("ul>li").not(":eq(0)").remove();
Copy after login

or

$("ul>li").not(":first").remove();
Copy after login

2 , use filter

$("ul>li").filter(function(index){ return index!=0; }).remove();
Copy after login

Related free learning recommendations:javascript(Video)

The above is the detailed content of How to dynamically delete LI using jQuery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!