Skip to content

Instantly share code, notes, and snippets.

@THEtheChad
Last active August 29, 2015 14:01
Show Gist options
  • Save THEtheChad/4f14ddaa7b7a7884dd61 to your computer and use it in GitHub Desktop.
Save THEtheChad/4f14ddaa7b7a7884dd61 to your computer and use it in GitHub Desktop.
// Store a copy of the original jQuery#removeClass method
var _originalMethod = $.prototype.removeClass;
// Replace the jQuery#removeClass method with our own
// custom function
$.prototype.removeClass = function(){
// Convert the arguments object into an array
var args = Array.prototype.slice.call(arguments);
// Call the original jQuery#removeClass method
// and pass it the current context and arguments.
// Record the response as well.
var response = _originalMethod.apply(this, args);
// Trigger our hook and pass it the current
// context and arguments
$(document).trigger('removeClass', {
context: this,
args: args
});
// Return the response from the original function
return response;
};
$(document).on('removeClass', function(evt, obj){
// obj.context is the element (or list of elements) who's class was removed
// obj.args are the original arguments passed to the jQuery#removeClass method
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment