The difference between jquery remove () and jquery Empty ()

Source: Internet
Author: User

The JQuery Remove () method deletes the selected element and its child elements. Examples are as follows:

1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <Scriptsrc= "/jquery/jquery-1.11.1.min.js"></Script>5 <Script>6 $ (document). Ready (function(){7   $("Button"). Click (function(){8     $("#div1"). Remove ();9   });Ten }); One </Script> A </Head> -  - <Body> the  - <DivID= "Div1"style= "height:100px;width:300px;border:1px solid black;background-color:yellow;"> - This is some text in the Div. - <P>This was a paragraph in the Div.</P> + <P>This is another paragraph in the Div.</P> - </Div> +  A <BR> at <Button>Delete div element</Button> -  - </Body> - </HTML>

Click the button before the following:

After clicking the button:

Remove () Removes the contents of the entire div-selected ID section.

The JQuery Empty () method deletes the child elements of the selected element.

Replace the Remove in the above code with empty () and click the button:

Empty () does not clear the selected part but clears the sub-section of the selected part.

The difference between jquery remove () and jquery Empty ()

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.