Skip to content

Instantly share code, notes, and snippets.

@qetr1ck-op
Last active January 21, 2016 13:27
Show Gist options
  • Select an option

  • Save qetr1ck-op/33dee329fe69c13b20e5 to your computer and use it in GitHub Desktop.

Select an option

Save qetr1ck-op/33dee329fe69c13b20e5 to your computer and use it in GitHub Desktop.
// Let's get hold of those elements
var outer = document.querySelector('#outer');
var inner = document.querySelector('#inner');
// Let's listen for attribute changes on the
// outer element
new MutationObserver(() => {
console.log('mutate');
}).observe(outer, {
attributes: true
});
// Here's a click listener…
function onClick() {
console.log('click');
setTimeout(() => {
console.log('timeout');
}, 0);
Promise.resolve().then(() => {
console.log('promise');
});
outer.setAttribute('data-random', Math.random());
}
// attach handler to both elements
inner.addEventListener('click', onClick);
outer.addEventListener('click', onClick);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment