Home > Web Front-end > JS Tutorial > jQuery implements dynamic deletion of LI instance sharing

jQuery implements dynamic deletion of LI instance sharing

小云云
Release: 2018-01-10 11:24:24
Original
1349 people have browsed it

This article mainly introduces jQuery's method of dynamically deleting LI, and analyzes jQuery's implementation techniques for dynamic operations of page elements in the form of examples. Friends in need can refer to it. I hope it can help everyone.

We sometimes 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 a ID, when the time comes, only the first

will be deleted. You can use


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

. This method can delete all other li's 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 recommendations:

javascriptHow to quickly dynamically delete and delete dom element code detailed explanation

How to implement dynamic deletion of javascript function_javascript skills

JS implementation How to dynamically delete specified rows from a table_javascript skills

The above is the detailed content of jQuery implements dynamic deletion of LI instance sharing. 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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template