Skip to content

Instantly share code, notes, and snippets.

@jozsefs
Last active October 26, 2016 12:03
Show Gist options
  • Select an option

  • Save jozsefs/09300acca86b8e37da435e7eee01b49e to your computer and use it in GitHub Desktop.

Select an option

Save jozsefs/09300acca86b8e37da435e7eee01b49e to your computer and use it in GitHub Desktop.
mutation observer example
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