Created
December 16, 2019 10:40
-
-
Save nickeforsberg/1c35a74617145cacfde199afae901aaf to your computer and use it in GitHub Desktop.
click-events.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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