Last active
October 26, 2016 12:03
-
-
Save jozsefs/09300acca86b8e37da435e7eee01b49e to your computer and use it in GitHub Desktop.
mutation observer example
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
| const observer = new MutationObserver((mutations) => | |
| mutations.forEach((mutation) => | |
| console.log(`New layout: ${mutation.target.getAttribute('data-layout')}`) | |
| ) | |
| ); | |
| observer.observe(document.body, { | |
| attributes: true, | |
| attributeFilter: ['data-layout'] | |
| }); | |
| // they will print the last value (large) due to dom is slower obv | |
| document.body.setAttribute('data-layout', 'small'); | |
| document.body.setAttribute('data-layout', 'medium'); | |
| document.body.setAttribute('data-layout', 'large'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment