The signature for your .on() and .off() should match.
These two do not match, so the .off() call will not find the appropriate event handlers to delete:
$(document).on('click', '.btn', function() { update(); }); $(document).off('click', '.blue');
Note. The selector passed to .on() and .off() is different.
When using the dynamic form .on() (where you pass the selector as an argument to .on ()), you cannot remove only part of the elements. This is because only one event handler is installed on the root element, and jQuery can delete only all or not at all. Thus, you cannot just .off() some of the dynamic elements.
Your parameters should remove all event handlers with:
$(document).off('click', '.btn');
and then install a new event handler that excludes items you don't want, for example:
$(document).off('click', '.btn:not(.blue)');
Or, teach the event handler itself how to ignore .blue elements:
$(document).on('click', '.btn', function() { if (!$(this).hasClass('blue')) { update(); } });
source share