Example of how to use the remove () method in jQuery, jqueryremove
This document describes how to use the remove () method in jQuery. Share it with you for your reference. The specific analysis is as follows:
This method deletes all matching elements from the DOM.
Note:The remove () method does not delete the matching elements from the jQuery object. Therefore, you can use these matching elements in the future. However, this element can be retained, other events, such as bound events and additional data, will be removed.
Syntax structure:
Copy codeThe Code is as follows: $ (selector). remove (expr)
Parameter List:
Parameters |
Description |
Expr |
Optional. JQuery expression used to filter elements |
Instance code:
Instance 1:
Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Meta name = "author" content = "http://www.bkjia.com/"/>
<Title> remove () function-helper's house </title>
<Script type = "text/javascript" src = "mytest/jQuery/jquery-1.8.3.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("Button"). click (function (){
$ ("Div"). remove ("# first ");
})
})
</Script>
</Head>
<Body>
<Div id = "first"> I am the first </div>
<Div id = "second"> I am the second </div>
<Button> click </button>
</Body>
</Html>
The following code deletes the div whose id is first in the div set.
Example 2:
Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Meta name = "author" content = "http://www.bkjia.com/"/>
<Title> remove () function-helper's house </title>
<Script type = "text/javascript" src = "mytest/jQuery/jquery-1.8.3.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("# Btd"). click (function (){
$ ("Div"). remove ();
})
})
</Script>
</Head>
<Body>
<Div id = "first"> I am the first </div>
<Div id = "second"> I am the second </div>
<Button id = "btd"> click to delete the first div </button>
</Body>
</Html>
If the parameter is omitted, all matching elements are deleted.
Example 3:
Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Meta name = "author" content = "http://www.bkjia.com/"/>
<Title> remove () function-helper's house </title>
<Style type = "text/css">
Div {
Width: 200px;
Height: 200px;
Border: 5px solid green;
}
</Style>
<Script type = "text/javascript" src = "mytest/jQuery/jquery-1.8.3.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("# Btd"). click (function (){
Var a = $ ("div ");
A. remove ("# first ");
$ ("# Btn"). click (function (){
Alert (a. length );
})
})
})
</Script>
</Head>
<Body>
<Div id = "first"> I am the first </div>
<Div id = "second"> I am the second </div>
<Button id = "btd"> Delete the first div </button> <button id = "btn"> View the number of div after the delete operation </button>
</Body>
</Html>
Remove () has deleted the match element in the DOM, but has not deleted it from the jquery object.
I hope this article will help you with jQuery programming.