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; }); 

jsfiddle


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -