Skip to content

Instantly share code, notes, and snippets.

@nickeforsberg
Created December 16, 2019 10:40
Show Gist options
  • Save nickeforsberg/1c35a74617145cacfde199afae901aaf to your computer and use it in GitHub Desktop.
Save nickeforsberg/1c35a74617145cacfde199afae901aaf to your computer and use it in GitHub Desktop.
click-events.js
// How to handle click events
// jQuery
$('.button').on('click', function() { /* handle click event */});
// Vanilla
// On one button
document.querySelector('.button').addEventListener('click', (e) => { /* handle click event */});
// On multiple buttons
document.querySelectorAll('.button').forEach((button) => {
button.addEventListener('click', (e) => {
/* handle click event */
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment