JavaScript copy node CloneNode () Use introduction

Source: Internet
Author: User
Tags shallow copy

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

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.