How jquery Inserts a node

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:<b> Hello </b></p>

appendto ()

Append all matching elements to the specified element

. In fact, using this method is reversed for $ (A) for general

. Append (b) is the operation of appending A to B.

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

jquery code:

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

result:

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

prepend () to each matching element internal Front content

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

result:

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

prependto () Put all matching elements in front of the specified element

. In fact, using this method reverses the

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

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

jquery Code:

result:

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

after ()

jquery code:

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

result:

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

insertafter ()

Inserts all matching elements into the specified element After

, in fact, using the method

is reversed for the regular $ (A). After (B) operation

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

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

result:

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

before ()

jquery code:

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

result:

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

InsertBefore ()

Inserts so that the matching element is inserted into the reference

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

Using this method is reversed by the general

The operation of the $ (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>


How jquery Inserts a node

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.