Blog Single Page

How to generate HTML with jquery clone with different names?

By on 26 April 2014

How to generate HTML with jquery clone with different names?





$("input#add").live( 'click', function(){
$("#main").append("
");
var cloned = $("#main div:last").clone(false).appendTo( $("#main") );
cloned.find('[name^=data]').attr('name', function() {
var index = this.name.match(/\[(\d)\]/);
if (index != null && index.length > 1) {
var newIndex = parseInt(index[1], 10) + 1;
return this.name.replace(/\[(\d)\]/, '[' + newIndex + ']');
}
return this.name;
});
});​

0 Replies to “How to generate HTML with jquery clone with different names?”

Leave a Reply

Your email address will not be published. Required fields are marked *

four × 5 =