JQuery DOM Insert node Operations Guide _jquery

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 general

The action of $ (A). Append (b) is to 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 ()

To place all matching elements in the specified element

。 In fact, using this method is upside down

General $ (A). prepend (B) operation.

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 into the specified meta

element of the back, in fact, using this method

is reversed the regular $ (a). After (B) operation

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 the matching element into the point

The front of the set element. As a matter of fact

Using this method is reversed the general

The operation of $ (A). Before (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>

The above is the entire content of this article, I hope you can enjoy.

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.