Example of how to use the remove () method in jQuery, jqueryremove

Source: Internet
Author: User

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.

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.