0

I have some id div with elements(classes and Ids), I need to clone it and append to my clone for exact Id data. How can I do it?

window.onload = Func ();

function Func () {

var temp = document.getElementById("start");
var cl = temp.cloneNode(true);
var div = document.createElement('div');
div.className = "class";
div.innerHTML = "MyText";
var result = cl.getElementById("second").append(div);
alert(result.innerHTML);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="start">
<div id="second">
<a href="#">Link</a>
</div></div>
Дмитрий
  • 83
  • 1
  • 10

1 Answers1

0
var item = document.getElementById("id1").lastChild;
var clone = item.cloneNode(true);
/*Id of the element below which you want to clone*/
document.getElementById("id2").appendChild(clone);
Aravind
  • 379
  • 4
  • 17