jquery - Remove cloned div except for the last one -
how remove last cloned div except first (default) div? http://jsfiddle.net/fj3bpyj2/
$('#addcontact').click(function() { $( "#contactinputs" ).clone().appendto( "#contactwrapper" ); return false; }); $('#removecontact').click(function() { $("#contactwrapper").find("#contactinputs").last().remove(); return false; });
try this
$('#removecontact').click(function () { var div = $("#contactwrapper > #contactinputs"); if (div.length > 1) div.last().remove(); return false; });
Comments
Post a Comment