Every time you click $('#deleteByID')
you are creating a new click handler for $('#revealYes,#revealNo')
that means the code that is executed
var choice = $(this).text();
if (choice == 'OK') {
deleteItemInCart(item5);
updateQtyLabel('qtyItem');
} else {
return false;
}
will be executed one extra time for each time you click on $('#deleteByID')
change your code so that the click handler for $('#revealYes,#revealNo')
is outside the other click handler
$('#deleteByID').click(function (e) {
if($('#modal').length == 0)
$('body').append(messageBox('heading','confirm','cancel'))
$('#modal').reveal({
animation: 'fade',
animationspeed: 320,
closeonbackgroundclick: true,
dismissmodalclass: 'close'
});
});
$(document).on('click','#revealYes,#revealNo',function (e) {
var choice = $(e.target).text();
if (choice == 'OK') {
deleteItemInCart(item5);
updateQtyLabel('qtyItem');
} else {
return false;
}
});
use delegate handlers rather than bind handlers to add handlers to dynamic elements