Can someone explain to me why, when I clone an element with jquery .clone()
, store it in $(windows).data('myclone')
and append this cloned data element to another element, the cloned data present in $(windows).data('myclone')
changes? (points toward my newly created element in html inspector)
<li class="clone">
<button class="file-list-delete"><a href="#">clone this</a>
</button>
<input type="file" size="30" id="files" multiple="multiple" name="files" class="upload-files">
</li>
<button id="append">append clone</button>
<script>
$('.clone button').on('click', function() {
var cloneNode = $(this).parent().clone();
$(window).data('cloneNode', cloneNode);
console.log(cloneNode);
});
$('#append').on('click', function() {
console.log($(window).data('cloneNode'));
var clone = $(window).data('cloneNode');
$('.clone').after(clone);
});
</script>
Here's a fiddle to see it in your console. First created element is just cloned data, then when you append it, it changes it http://jsfiddle.net/50eu0bnp/