Questions tagged [clonenode]

The Node.cloneNode() method returns a duplicate of the node on which this method was called.

From Mozilla Developer Network:

The Node.cloneNode() method returns a duplicate of the node on which this method was called.

Cloning a node copies all of its attributes and their values, including intrinsic (in–line) listeners. It does not copy event listeners added using addEventListener() or those assigned to element properties. (e.g. node.onclick = fn) Moreover, for a element, the painted image is not copied.

The duplicate node returned by cloneNode() is not part of the document until it is added to another node that is part of the document using Node.appendChild() or a similar method. It also has no parent until it is appended to another node.

If deep is set to false, child nodes are not cloned. Any text that the node contains is not cloned either, as it is contained in one or more child Text nodes.

If deep evaluates to true, the whole subtree (including text that may be in child Text nodes) is copied too. For empty nodes (e.g. <img> and <input> elements) it doesn't matter whether deep is set to true or false.

123 questions
1
vote
2 answers

javascript: cloning an object and its nodes

I couldn't seem to find quite what I'm looking for in any other question. I am wondering if there is a way to clone an object and its DOM nodes. I have tried: newObj = jQuery.extend(true, {}, oldObj); but this does not clone any of the nodes, and…
Greg Rozmarynowycz
  • 2,037
  • 17
  • 20
1
vote
0 answers

Create a New onclick function for each element created

I am building a website that takes in unique information (such as shareholder info and loan info) about specific store clients and stores them. Because it is impossible to know how many shareholders/lenders a client has, the website has the ability…
Deji James
  • 367
  • 6
  • 20
1
vote
1 answer

Clone

I have a div with id="add-dependent" including 2 rows and a button (add dependent) inside of the div. When "add dependent" button is clicked, the first row would be cloned and insert before (add dependent) button. Actually I have another button…
1
vote
2 answers

Property 'id' does not exist on type 'Node' in plain JS after cloneNode

I've got a pure JS function that adds a message to the page based on a chunk of "template" HTML. const setMessage = (msg, type, msg_ct) => { const msg_text = document.createTextNode(msg) const elementToCopy =…
michjnich
  • 2,796
  • 3
  • 15
  • 31