Without further ado, I will post the code directly for you. The specific code is as follows:
<html> <head> <meta charset="utf-8"> <title></title> <style> ul { list-style: none; } li { line-height: 25px; margin-top: 3px; } li:hover { background-color: #ddd; } li.hover { background-color: #fc0; } </style> <script src="./jquery-2.2.4.min.js"></script> <script type="text/javascript"> $(function() { //获取每一个li节点并设置点击事件 $("li").click(function() { //当点击某一个节点的时候,增加类名为hover $(this).toggleClass("hover"); }); //获取删除按钮并设置点击事件 $("button").click(function() { //将类名是hover的节点删除 $("li.hover").remove(); }); }); </script> </head> <body> <h2 id="hid">jQuery实例--节点删除</h2> <ul> <li>asdfasdfasfd</li> <li>asdfasdfasfd</li> <li>asdfasdfasfd</li> <li>asdfasdfasfd</li> <li>asdfasdfasfd</li> <li>asdfasdfasfd</li> </ul> <button>删除</button> </body> </html>
The above is the jQuery implementation introduced by the editor. I hope this method of deleting li nodes will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank you all for your support of the php Chinese website!
For more jQuery related articles on how to delete li nodes, please pay attention to the PHP Chinese website!