How to add a new element children in child behind the last element of the current node

Use ParentNode.append (), such as the following is a child element node is added under the body element node: 

var parent = the document.body; 

// add an element child nodes 
var P = document.createElement ( 'P' ); 
parent.append (P); 

// add text child 
parent.append ( 'the Hello' ); 

// add a plurality of element children 
var P1 = document.createElement ( 'P' );
 var P2 = document.createElement ( 'P' ); 
parent.append (P1, P2); 

// add elements and text node child node 
var P document.createElement = ( 'P' ); 
parent.append ( 'the Hello', P);

 

note: 

1. The plurality of nodes may be added, but only the node type of node is an element or a text node;

2. A new node is located behind a last child node of the current node, i.e.: adding;

Guess you like

Origin www.cnblogs.com/aisowe/p/11528877.html