The Remove () method usage instance in jquery _jquery

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.