Last active
September 26, 2018 13:48
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 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