A simple task of cloning an element and autoincrement its id.
can it be done in 1 line?
A simple task of cloning an element and autoincrement its id.
can it be done in 1 line?
jQuery
var NewElement=$("#test1").clone(); // Clone the element
var IDNr=NewElement.attr("id").match(/\d+$/); // Grab the ID number
NewElement.attr("id",NewElement.attr("id").replace(IDNr,parseInt(IDNr)+1)); // Increment the ID
HTML
<div id="test1">Test</div>