JS Native Append child node

Source: Internet
Author: User

var fragment = Document.createdocumentfragment (); li = document.createelement (' li '); li.classname = "xxx"; Fragment.appendchild (LI);  document.getElementById ("xx"). appendchild (fragment);

As above, it is necessary to create the node first, the node content becomes a part of the document talent appendchild. Suppose that direct appendchild ("<div></div>") is not possible. Since appendchild (node) is usually joined after the last child node of the specified element node but assumes that node is a DOM object in the page, then it is not a join node, it is a direct move node. AppendChild you can understand to move an element. If you want to copy a past, clone in advance but in any case, this node needs to exist first. Append () is preceded by the object to be selected, followed by the element content to be inserted inside the object

AppendTo () is preceded by the content of the element to be inserted and is a jquery object. And back is the object to select

Instance:


A purely personal point of view. I hope you have the wrong advice, thank you

JS native Append child nodes

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.