Node Insertion method

Source: Internet
Author: User
Method Describe Example
Append () Append content to each matching element

HTML code:

<p> I want to say:</p>

jquery Code:

$ ("P"). Append ("<b> Hello </b>")

Results:

<p> I want to say hello,:<b> </b></p>

Appendto ()

Appends all matching elements to the specified element.

In fact, using this method reverses the conventional

$ (A). Append (b) operations, that is, not append B to

A, but append a to B

HTML code:

<p> I want to say:</p>

jquery Code:

$ ("<b> Hello </b>"). Appendto ("P")

Results:

<p> I want to say hello,:<b> </b></p>

Prepend () Forward content to each matching element

HTML code:

<p> I want to say:</p>

jquery Code:

$ ("P"). prepend ("<b> Hello </b>")

Results:

<p><b> Hello </b> i want to say:</p>

Prependto ()

All matching elements are placed in front of the specified element.

In fact, using this method reverses the conventional

$ (A). Prepend (b) operation, that is, not to place B before

A, instead of placing a in front of B

HTML code:

<p> I want to say:</p>

jquery Code:

$ ("<b> Hello </b>"). Prependto ("P")

Results:

<p><b> Hello </b> i want to say:</p>

After () Insert content after each matching element

HTML code:

<p> I want to say:</p>

jquery Code:

$ ("P"). After ("<b> Hello </b>")

Results:

<p> I want to say hello,:</p><b> </b>

InsertAfter ()

Inserts all matching elements behind the specified element.

In fact, using this method reverses the conventional

$ (A). After (b) operation, that is, not inserting B into a

Behind, but instead inserts a after B

HTML code:

<p> I want to say:</p>

jquery Code:

$ ("<b> Hello </b>"). InsertAfter ("P")

Results:

<p> I want to say hello,:</p><b> </b>

Before () Insert content before each matching element

HTML code:

<p> I want to say:</p>

jquery Code:

$ ("P"). Before ("<b> Hello </b>")

Results:

<b> Hello </b><p> i want to say:</p>

InsertBefore ()

Inserts all matching elements in front of the specified element.

In fact, using this method reverses the conventional

$ (A). Before (b) operation, that is, not inserting B

To the front of a, instead of inserting a in front of B

HTML code:

<p> I want to say:</p>

jquery Code:

$ ("<b> Hello </b>"). InsertBefore ("P")

Results:

<b> Hello </b><p> i want to say:</p>

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.