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