Analysis of append () and appendto () usage in jquery, jqueryappendto

Source: Internet
Author: User

Analysis of append () and appendto () usage in jquery, jqueryappendto

This document analyzes the usage of append () and appendto () in jquery. Share it with you for your reference. The specific analysis is as follows:

In jQuery's document operation methods, the append () and appentto () Methods perform the same task, but there are also differences between the two.

1. append () method:Insert the specified content at the end of the selected element (but still inside the element.

A. Syntax:Copy codeThe Code is as follows: $ (selector). append (content); where the parameter content is required and the content to be appended is specified.

B. The append function can be used to add content to the selected element. Syntax:Copy codeThe Code is as follows: $ (selector). append (function (index, html); where function () is required and the index and html parameters are optional. Index indicates the index position of the receiving selector, and html indicates the current html of the receiving selector.

Example:
Copy codeThe Code is as follows: <Head>
<Script type = "text/javascript" src = "/jquery. js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("Button"). click (function (){
$ ("P"). append ("<B> Hello jQuery! </B> ");
});
});
</Script>
</Head>
<Body>
<P> This is a paragraph. </p>
<P> This is another paragraph. </p>
<Button> add content at the end of each p element </button>
</Body>
</Html>

The running result is as follows:

This is a paragraph. Hello jQuery!
This is another paragraph. Hello jQuery!

2. appendto () method:Insert the specified content at the end of the selected element (but still inside the element. However, functions cannot be used to Append content.

Syntax:Copy codeThe Code is as follows: $ (content). appendto (selector );

Example:
Copy codeThe Code is as follows: <Head>
<Script type = "text/javascript" src = "/jquery. js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("Button"). click (function (){
$ ("<B> Hello jQuery! </B> "). appendTo (" p ");
});
});
</Script>
</Head>
<Body>
<P> This is a paragraph. </p>
<P> This is another paragraph. </p>
<Button> add content at the end of each p element </button>
</Body>
</Html>
The running result is as follows:

This is a paragraph. Hello jQuery!
This is another paragraph. Hello jQuery!

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.