The jQuery element removes the difference between empty () remove () and detach ()?

Source: Internet
Author: User

@1.empty () deletes all descendant byte point elements in the matching element collection ;

<p>hello<span>world</span></p>

$ ("P"). empty (); <p></p>

@2.remove ([expr]) receives a parameter that deletes the specified element

$ ("P"). Remove () Delete all paragraphs

$ ("P"). Remove (". Hel") deletes a paragraph with a. Hel class name

This method does not remove the matching elements from the jquery object, so that the matching elements can be used in the future. Except that the element itself is preserved, other things such as bound events, attached data, etc. are removed .

@3.detach ([Expre]) removes all matching elements from the DOM

This method does not remove the matching elements from the jquery object, so that the matching elements can be used in the future. Unlike remove (), all bound events, attached data, and so on will remain

<body>

<div id= "Google" >Google</div>

<div id= "Apple" >Apple</div>

</body>

<script type= "Text/javascript" >

$ (function () {

$ ("#apple"). Hover (function () {

$ (this). Text ("Google +");

});

Apple = $ ("#apple"). Remove (); <!--//Use the Remove () hover () event will also be removed-

/*apple = $ ("#apple"). Detach ();*/<!--//using the detach () hover () event is saved--

$ ("Body"). Append (Apple);

});

</script>

The jQuery element removes the difference between empty () remove () and detach ()?

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.