3

I am new in Javascript.I need to add duplicate same elements when I click on add more button to add the whole body elements dynamically.Here are the image of my code

Image

How to do that ? I need your suggestion.Thanks in advance.

Liam
  • 27,717
  • 28
  • 128
  • 190
Nijar Hossain
  • 129
  • 2
  • 10

2 Answers2

2

You can do it with native javascript

element2 = element1.cloneNode(bool)

Here boolean indicates whether to clone child nodes or not

Gaurav Aggarwal
  • 9,809
  • 6
  • 36
  • 74
2

You can do it easily in js easily via cloneNode

function cloneFunction() {
    var para = document.getElementById("para-1");
    var cln = para.cloneNode(true);
    document.getElementById("parent").appendChild(cln);
}
<div id="parent">
<p id="para-1">Lorem Ipsum</p>
</div>

<button onclick="cloneFunction()">clone it</button>
Arun Sharma
  • 1,331
  • 8
  • 11