I was looking into removing multiple inputs and selects at once using jQuery, but I couldn't find a solution, so I ended up with the following code:
$(function() {
$('a.add').click(function(evt) {
//clone lists
//is there any way to simplify this part --begin--
$('#s0 option').clone().appendTo('#s'+obj);
$('#i0 option').clone().appendTo('#i'+obj);
$('#r0 option').clone().appendTo('#r'+obj);
$('#ieu0 option').clone().appendTo('#ieu'+obj);
$('#ied0 option').clone().appendTo('#ied'+obj);
//--end--
evt.preventDefault(); //prevents scrolling
});
//remove inputs/selects
$('a.remove').click(function(evt) {
//animation is not necessary. How can I simplify this code? --begin--
$('#comp'+x).animate({opacity:"hide"}, "slow").remove();
$('#ppt'+x).animate({opacity:"hide"}, "slow").remove();
$('#ct'+x).animate({opacity:"hide"}, "slow").remove();
$('#p'+x).animate({opacity:"hide"}, "slow").remove();
$('#ipvs'+x).animate({opacity:"hide"}, "slow").remove();
$('#s'+x).remove();
$('#i'+x).remove();
$('#r'+x).remove();
$('#ipvs'+x).remove();
$('#other'+x).remove();
//--end--
}
evt.preventDefault();
});
});
How can the sections marked between --begin-- and --end-- be simplified/improved? Thanks !
.each()
– zzzzBov Aug 21 '12 at 18:10,
to separate them. – Ricardo Lohmann Aug 21 '12 at 18:12