(function($){ var remove_orig = $.fn.remove; $.fn.remove = function(){ console.log('Remove called'); remove_orig.apply(this, arguments); }; })(jQuery);
You can βconnectβ to any jQuery function and put your own processing code inside (including the logging method), which will be executed before the jQuery native code is executed.
demo (another version with selector shown)
Catching deletion is easy using the above overload. Just change the binding to trigger the trigger before (or after) jQuery:
(function($){ var remove_orig = $.fn.remove; $.fn.remove = function(){ this.trigger('removing'); remove_orig.apply(this, arguments); }; })(jQuery); $('#foo').bind('removing',function(e){ alert('#foo is being removed'); }); $('#foo').remove();
source share