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();
. 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); } }); } });
There are many methods, you can also use:
1, use not
$("ul>li").not(":eq(0)").remove();
or
$("ul>li").not(":first").remove();
2. Use filter
$("ul>li").filter(function(index){ return index!=0; }).remove();
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!