I have the following function
function removecost(e,parent) {
e.preventDefault();
var current_Explanation = parent;
var other_Explanations = current_Explanation.siblings('.repeatingcostsection');
if (other_Explanations.length === 0) {
alert("You should atleast have one Cost Section");
return;
}
current_Explanation.slideUp('slow', function() {
current_Explanation.remove();
// reset Explanation indexes
other_Explanations.each(function() {
resetAttributeNames($(this));
})
})
}
The function doesn't do any special. It is called on a delete icon's onclick attribute and checks the number of siblings for current_Explanation
. If they are greater than zero then it removes current_Explanation. If the siblings length is 0 then it alerts a message "You should atleast have one Cost Section".
The functionality works absolutely fine if the user clicks slowly on the icon. But if user clicks clicks continuously very fast on the icon, the alert message is not shown and all blocks are removed because
I think
other_Explanations.each(function() { resetAttributeNames($(this)); });
is not completed properly.