Skip to content

Instantly share code, notes, and snippets.

@sontd-0882
Created March 3, 2020 06:40
Show Gist options
  • Save sontd-0882/2747f1aeac6b0e7f7124987823d5b2cb to your computer and use it in GitHub Desktop.
Save sontd-0882/2747f1aeac6b0e7f7124987823d5b2cb to your computer and use it in GitHub Desktop.
Listen child event from document
document.addEventListener('click', (event: Event) => {
const target = event.target as Element;
const button = target.closest('.btn');
if (!button) return;
const color = window
.getComputedStyle(button)
.getPropertyValue('background-color');
button.classList.add('ripple');
setTimeout(() => button.classList.remove('ripple'), 700);
console.log('is .btn?', !!target.closest('.btn')); // eslint-disable-line
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment