javascript - cloning a form with jquery and remove attributes -
is possible clone form without disturbing functionality ?
indeed, id of form duplicate. 2 dom objects same id forbidden.
<form id='originalform' name='originalform' enctype='multipart/form-data' action=''> <input id='firstname' name='firstname' type='text'/> <input id='lastname' name='lastname' type='text' /> <input id='photo' name='photo' type='file' /> </form> ... var copyform = jquery('#originalform').clone(); var e = copyform.find(':input').not(':file'); e.each(function() { jquery($this).removeattr('name'); }
var originalform = jquery('#originalform'); //clone form var newform = originalform.clone(); //change form id newform.attr('id', 'newid'); //remove `name` attr non file inputs newform.find('input:not(:file)').removeattr('name'); //add new form page after old 1 originalform.after(newform);
Comments
Post a Comment