JQuery DOM insert node operation guide

Source: Internet
Author: User

JQuery DOM insert node operation guide

This topic describes jQuery's methods for dynamically inserting nodes in HTML. You can create a table to facilitate comparison and learning. For more information, see

Method Description Example
Append () To each matched elementInternalAppend content

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

JQuery code:

$ ("P"). append ("<B> Hello </B> ");

Result:

<P> I want to say: <B> Hello </B> </p>

AppendTo ()

Append all matched elements to the specified element.

. In fact, this method is used to reverse the General

The $ (A). append (B) Operation of is to append 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 matched elementInternalPre-content

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

JQuery code:

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

Result:

<P> <B> Hello </B> I want to say: </p>

PrependTo ()

Forward all matched elements to the specified element.

. In fact, this method is reversed.

Regular $ (A). prepend (B) operations.

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

JQuery code:

$ ("<B> Hello </B>"). prependTo ("p ")

Result:

<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> ")

Result:

<P> I want to say: </p> <B> Hello </B>

InsertAfter ()

Inserts all matching elements into the specified element.

Actually, this method is used.

The regular $ (A). after (B) operations are reversed.

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

JQuery code:

$ ("<B> Hello </B>"). insertAfter ("p ")

Result:

<P> I want to say: </p> <B> Hello </B>

Before () Insert content before each Matching Element

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

JQuery code:

$ ("P"). before ("<B> Hello </B> ")

Result:

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

InsertBefore ()

Insert the matched element to the specified

Before the specified element. Actually,

This method is used to reverse the General

$ (A). before (B.

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

JQuery code:

$ ("<B> Hello </B>"). insertBefore ("p ")

Result:

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

The above is all the content of this article. I hope you will like it.

Related Article

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.