This article mainly introduced the JavaScript node operation copy node CloneNode () The use, needs the friend may refer to under
The CloneNode (a) method accepts a Boolean parameter that indicates whether a deep copy is true: A deep copy is performed, the node is replicated, and the entire child node tree is copied. False: Shallow copy. Only the node itself is replicated. The copy of the node returned after the copy belongs to the document, but does not have a parent node. Unless you use Appendchild,insertchild (), replacechild () adds it to the document code as follows: <div id= "Guodiv" > < span>1</span> <span>2</span> <span>3</span> </div> var odiv = Document.getelem Entbyid ("Guodiv"); var deeplist = Odiv.clonenode (true); Copy child Node alert (deepList.childNodes.length); 3 or 7 (compatibility problem, so the result is not the same) var showlist = Odiv.clonenode (false); Copy only the current element's Reference alert (showList.childNodes.length); 0