javascript - Duplicate DOM node jQuery (not reference) -


i developing dynamic form, , need duplicate node , insert dom position.

my problem when first copy node (which contains empty inputs), fill data, , copy again, copied data.

i duplicate variable containing empty dom node , not refer it.

it's possible?

var emptysegment = $( '#segment' ).clone();  $(document ).on('click', '#add', function(){     var emptysgmt = emptysegment; // duplicate emptysegment.      emptysgmt.insertafter( '.lastsegment' ); }); 

thank you

after clone element need reset input (or other elements) state require. try this:

$(document).on('click', '#add', function() {     clonesegment().insertafter('.lastsegment'); });  function clonesegment() {     return $('#segment').clone().find('input').val('').end(); } 

note example resets value of input elements within segment. can put own logic in there meet whatever specific requirements are.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -