AppendChild Append InsertBefore prepend

Source: Internet
Author: User

createtime--2017 November 2 16:57:59

Author:marydon

difference between appendchild () and append () InsertBefore () and prepend ()

C. Inserting a child node at the end of the parent element
JavaScript mode

AppendChild ("This can only be a LABEL element"),

such as: appendchild (' div '), want to specify the label style and the contents of the tag body, you need to create a dynamic element and specify attributes, and then stitch

Example:

// The body tag adds a child node document.body.appendChild (Divtag);

jquery Way

Append ("Can directly splice HTML fragments or text content")
Example:

// method One $ ("Body"). Append (Divtag); // method Two $ ("Body"). Append ("<div id= ' test ' ></div>")

D. Inserting a child node at the front of the parent element
Inserts a sibling node before a specified sibling element
JavaScript mode

InsertBefore (target object, insertion position)
This method can only complete the concatenation of the child nodes through the parent node.

Example:

// insert a sibling node in front of a tag var aTag = document.getElementById ("Test");d Ocument.body.insertBefore (divtag,atag);

jquery Way

Prepend ("Can directly splice HTML fragments or text content")
Example:

$ ("#test"). Prepend (Divtag);

</div

AppendChild Append insertbefore prepend

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.