If an element in the document is redundant, delete it. JQuery provides two methods to delete nodes: The remove () method and the empty () method.
1. remove ():
Copy codeThe Code is as follows:
<% @ Page contentType = "text/html; charset = UTF-8" pageEncoding = "UTF-8" %>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> Insert title here </title>
<Script src = "jQuery/jquery-1.10.2.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("Ul li: eq (1)"). remove ();
});
</Script>
</Head>
<Body>
<P title = "what kind of fruit do you like best? "> What is your favorite fruit? </P>
<Ul>
<Li title = "apple"> apple </li>
<Li title = "orange"> orange </li>
<Li title = "banana"> bananas </li>
</Ul>
</Body>
</Html>
When a node is deleted using the remove method, all child nodes contained in the node will be deleted at the same time. The return value of this method is a reference pointing to the deleted node.
In addition, the remove () method can also selectively Delete elements by passing parameters.
Copy codeThe Code is as follows:
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("Ul li"). remove ("li [title! = Apple] ");
});
</Script>
2. empty ():
Strictly speaking, the empty method does not delete nodes, but clears nodes. It can clear all child nodes in the element.
Copy codeThe Code is as follows:
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("Ul li: eq (1)"). empty ();
});
</Script>
View the page source code: