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
3
votes
2 answers

Setting an attribute of a child

I have cloned a node, but i want to set or change an attribute of a div inside that cloned node, specifically, change the id of div id="test0" I can't find any documentation out there on this, any straight JavaScript guys out there know a…
Joel Grannas
  • 2,016
  • 2
  • 24
  • 46
3
votes
1 answer

Vertical Marquee remove space

I want to include some vertical marquee text to my page
so that the content will be automatically scrolled. I found the following code useful;
Alfred
  • 21,058
  • 61
  • 167
  • 249
2
votes
1 answer

Within Javascript is there a way to duplicate an HTML wrapper without its "Event Listeners" losing their functionality?

So within my Javascript I am able to duplicate my HTMl Id="characters" wrapper only once. I know it should technically be a "class" rather than an "Id" because it will be a duplicated "Id", but for some reason I don't get; when I change my…
SamBoone
  • 39
  • 7
2
votes
1 answer

create a new id for each clone

I am trying to clone a div in a form while also giving each input a unique id. I have reproduced quite a bit of code but it's for a wholistic understanding of what I am trying to create. Below is my html for the code:
Kola Ayanwale
  • 105
  • 1
  • 8
2
votes
1 answer

Why does using cloneNode() to create multiple audio files stop me from controlling attributes of the audio source as and how can I override this

I've been making web games for sometime now and I quickly noticed that once i use the .cloneNode(true) to play back the same audio file multiple times to avoid re-downloading the file over and over each time I want to play an audio file, I loose…
Vachila64
  • 23
  • 6
2
votes
4 answers

JavaScript add element method doubling not adding

I'm trying to use JavaScript to create copies of a div element when a button is clicked. I'm using the .cloneNode() method, but it's multiplying the results. Initially there is one instance of the element on the page; on click that doubles to 2,…
Anon_guy
  • 155
  • 10
2
votes
1 answer

Native way to copy all child nodes to an other element

I have to change "unknown" contents of XML. The structure and content itself is valid. Original asas
... …
kroko
  • 65
  • 2
  • 8
2
votes
1 answer

documentFragment.cloneNode(true) doesn't clone jQuery data

I have a documentFragment with several child nodes containing some .data() added like so: myDocumentFragment = document.createDocumentFragment(); for(...) { myDocumentFragment.appendChild( $('').addClass('button') .attr('href',…
taber
  • 3,166
  • 4
  • 46
  • 72
2
votes
3 answers

how to 'getelementsbytagname.onclick'

I am trying to get my cloneNode to append the input tag and give it a new onclick value. Its just the input.onclick = function(){clicker(iden);}; that doesn't work. The sole purpose of this example is to change the onclick tag like I managed to…
Karl Stulik
  • 961
  • 1
  • 12
  • 24
2
votes
1 answer

Does IE 11 support deep cloneNode?

In IE up until version 10, deep cloning of nodes using cloneNode is not supported. For IE I am using innerHTML for cloning. Will cloneNode(true) work in IE 11? Is this supported in IE 11? (I have no way to test this)
Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168
1
vote
2 answers

cloning a html div element on canvas without using any libraries

Get a html div element cloned on canvas with clone node. Is there a way to get it done. Is there any way to get a html element (a div and a paragraph inside the div with height and width of 100px and background color which makes it look like a…
Latha G M
  • 11
  • 2
1
vote
1 answer

I've nodeClone() a div. I want the element to show only one day in each clone not the whole array

let divToClone = document.querySelector('.div-to-clone'); let target1 =…
XYz o
  • 11
  • 3
1
2
3
8 9