Skip to content

Instantly share code, notes, and snippets.

@ekwoster
Created June 29, 2017 09:43
Show Gist options
  • Save ekwoster/30e55fb5f9ae170eedfe258430fd09ec to your computer and use it in GitHub Desktop.
Save ekwoster/30e55fb5f9ae170eedfe258430fd09ec to your computer and use it in GitHub Desktop.
jQuery Class Changed Event
(function(){
var originalAddClassMethod = jQuery.fn.addClass;
var originalRemoveClassMethod = jQuery.fn.removeClass;
jQuery.fn.addClass = function(){
var result = originalAddClassMethod.apply( this, arguments );
jQuery(this).trigger('classChanged');
return result;
}
jQuery.fn.removeClass = function(){
var result = originalRemoveClassMethod.apply( this, arguments );
jQuery(this).trigger('classChanged');
return result;
}
})();
@LordPachelbel
Copy link

This was very helpful for me today. Thanks!

@cavasinf
Copy link

cavasinf commented Jul 22, 2020

Does this work with :

$element[0].classList.add('my-class');

EDIT : Yes it does ! Thank you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment