This article mainly introduces jquery's function of deleting all elements after an element, which is simple and convenient, interested friends can refer to the examples in this article to share with you the detailed implementation process of jquery to delete all elements after an element. the specific implementation content is as follows:
Effect:
Select project
Click the delete button to delete all elements of the same level after the option is selected.
The nextAll () method traversed by jQuery can be used to search for sibling elements following the elements in the DOM tree, that is, all sibling elements following an element. to delete an element, you can use the remove () method.$ (Selector). nextAll (). remove ();
The following is an example: click the button to delete all the options after the selected project
Create Html elements
Click the button to delete all options after the selected project.
RadishVegetablesScallions
TofuTudouEggplant
Set the css style
p.box{width:300px;height:200px;padding:10px 20px;border:4px dashed #ccc;}p.box>span{color:#999;font-style:italic;}p.content{width:250px;height:100px;margin:10px 0;border:1px solid green;}input{margin:10px;}input[type='button']{width:200px;height:35px;margin:10px;border:2px solid #ebbcbe;}
Compile jquery code
$(function(){ $("input:button").click(function() { $("input:checkbox:checked").next().nextAll().remove(); });})
The above are the knowledge points prepared by Xiaobian for you. I hope you can master them well.