jquery Append,appendto,prepend,prependto Introduction

Source: Internet
Author: User

Learning this chapter in the jquery authoritative guide, it is necessary to introduce the contents:

The first is the append (content) function:

It means adding content to the contents of the selected object.

For example: $ ("div"). Append ("<p>" + Hello + "</p>");

Add a P tag to all DIV elements, the tag content is Hello, and if there is other content inside the div element, add new content after the original content

Then there is the appendto (content) function:

By the word "to" we will know what this function means to add to what, so it is the biggest difference with the append () function:

The location of content and selectors, and append () can use functions to attach content. and the tasks they perform are the same.

As the above example:

$ ("div"). Append ("<p>" + Hello + "</p>"); add P tag to all div in page

If you use Appendto, you should write this:

$ ("<p>" + Hello + "</p>"). AppendTo ("div")

There's another form of append.

Append (function (index,html) {})

The usage is the same as the original append, but the index and HTML in the function do not take for granted that it is inserted under the first index Div HTML content, in fact, these two parameters are only used to return the current object's index value and the original content

jquery Code

$ (function() {            $ ("div"). Append (function(n,m) {                                    return "Hello" + "index value:" + N + "original content:" + m;            });        })

HTML code

     <P>Hello</P>     <Div>JQuery 1</Div>     <Div>JQuery 2</Div>     <Div>JQuery 3</Div>     <Div>JQuery 4</Div>

Browser results:

The usage of prepend and prependto is the same as that of append,appendto, except that prepend and prependto Add new content in front of the selected object content.

JQuery append,appendto,prepend,prependto Introduction

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.