javascript - jquery on() method Maximum call stack size exceeded -


why getting error:

uncaught rangeerror: maximum call stack size exceeded

here code:

$(document).on('keypress focusout', '.checklist-item-input', function (e) {   if (e.which == 13 || e.type == 'focusout') {     $('.checklist-item').removeclass('edit');     $(this).siblings('.checklist-item-detail').text($(this).val());     $(this).blur();     $('.checklist-item-detail').each(function () {       if (!$(this).text().length) {         $(this).closest('.checklist-item').parent().remove();       }     });   } }); 

as others mentioned cause recursive call. 1 simple fix add sentinel variable stop going recursive:

var busy = false; $(document).on('keypress focusout', '.checklist-item-input', function (e) {   if (!busy && e.which == 13 || e.type == 'focusout') {     busy = true;     $('.checklist-item').removeclass('edit');     $(this).siblings('.checklist-item-detail').text($(this).val());     $(this).blur();     $('.checklist-item-detail').each(function () {       if (!$(this).text().length) {         $(this).closest('.checklist-item').parent().remove();       }     });     busy = false;   } }); 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -