Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save takahirohonda/67167861e636309108fe51893a842d4f to your computer and use it in GitHub Desktop.
Save takahirohonda/67167861e636309108fe51893a842d4f to your computer and use it in GitHub Desktop.
better-way-to-attach-event-listener-with-vanilla-js-4-closest.js
document.querySelector('.my-form')
.addEventListener('change', (e) => {
if (e.target.closest('.radio-input') !== null) {
console.log(`${e.target.value} is picked`);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment