How can i change the id while cloning?
Example:
<div id="unique" class="cloneMe">test</div>
<div id="unique1" class="cloneMe">test</div>
<div id="unique2" class="cloneMe">test</div>
Script
jQuery('.cloneMe').clone(); // has all selected after cloning
...
Result
<div id="unique" class="cloneMe">test</div>
<div id="unique1" class="cloneMe">test</div>
<div id="unique2" class="cloneMe">test</div>
<div id="unique" class="cloneMe">test</div>
<div id="unique1" class="cloneMe">test</div>
<div id="unique2" class="cloneMe">test</div>
How can i explicitly modify only the cloned div?
You can use each
and then set a new id.
jQuery('.cloneMe').clone().each(function(i){
this.id = "id"+ i; // to keep it unique
}).appendTo("someSelector");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With