This example describes the use of the Remove () method in jquery. Share to everyone for your reference. The specific analysis is as follows:
This method will remove all matching elements from the DOM.
Note:the Remove () method does not remove the matching elements from the jquery object, so you can use these matching elements in the future, but except that the element itself is preserved, other such as bound events, additional data will be removed.
Syntax structure:
Copy Code code as follows:
$ (selector). Remove (expr)
Parameter list:
| Parameters |
Describe |
| Expr |
Optional. jquery Expressions for filtering elements |
Instance code:
Example one:
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title>remove () function-cloud-dwelling community </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>
<body>
<div id= "First" > I'm number one </div>
<div id= "Second" > I am the second </div>
<button> Click </button>
</body>
The following code can delete a div with id A in the DIV collection.
Example two:
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title>remove () function-cloud-dwelling community </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>
<body>
<div id= "First" > I'm number one </div>
<div id= "Second" > I am the second </div>
<button id= "BTD" > click to delete the first div</button>
</body>
If you omit the argument, it is the deletion of all matching elements.
Example three:
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title>remove () function-cloud-dwelling community </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>
<body>
<div id= "First" > I'm number one </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>
Remove () has removed a matching element from the DOM, but it has not been removed from the jquery object.
I hope this article will help you with your jquery programming.