Skip to content

Instantly share code, notes, and snippets.

@tallesairan
Last active September 26, 2018 13:48
Show Gist options
  • Save tallesairan/2d9035abf35cf72c6b7baac829dcbce3 to your computer and use it in GitHub Desktop.
Save tallesairan/2d9035abf35cf72c6b7baac829dcbce3 to your computer and use it in GitHub Desktop.
Class change Observer with MutationObserver read more at https://developer.mozilla.org/pt-BR/docs/Web/API/MutationObserver
/// read more at
var $div = $(".card");
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName === "class") {
var attributeValue = $(mutation.target).prop(mutation.attributeName);
console.log("Class attribute changed to:", attributeValue);
console.log($(mutation.target));
$( document ).trigger( "validateCard", attributeValue );
}
});
});
observer.observe($div[0], {
attributes: true
});
$( document ).on( "validateCard", {
button: "allow"
}, function( event, card ) {
console.log( event.data.foo ); // "bar"
console.log( card ); // "bim"
});
$( document ).trigger( "validateCard", [ "bim", "baz" ] );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment