//I am cloning a dom element and inserting it in dom element multiple times
<div class='toBeCloned'>some text</div>
<div id='target'></div>
var _clone=$('.toBeCloned').clone(true);//create clone
var _target=$('#target'); //this is target
_target.append(_clone); //append target
_target.append(_clone); //append target
_target.append(_clone); //append target
//this should add 3 elements but it's adding only one
//I am cloning a dom element and inserting it in dom element multiple times
Share
appendis a bit odd here – it moves the element, but it might also clone it if you append it to more than one element (eg$(div).appendwill clone the element for every div).If you want to create 3 elements, simply call
clone3 times: