Skip to content

Instantly share code, notes, and snippets.

@pardamike
Last active December 1, 2017 06:46
Show Gist options
  • Save pardamike/f6cf94697702274fb2933e9a34cbf60e to your computer and use it in GitHub Desktop.
Save pardamike/f6cf94697702274fb2933e9a34cbf60e to your computer and use it in GitHub Desktop.
/* Attaching event listners with jQuery method 1: */
$('#someElement').click(function (event) {
// Do something with the event
});
/* Attaching event listners with jQuery method 2: */
$(document).on('click', '#someElement', function (event) {
// Do something with the event
});
/* Attaching event listeners with Javascript */
document.getElementById('someElement').addEventListener('click', function (event) {
// Do something with the event
});
/* You can also do click events in JS this way */
document.getElementById('someElement').onclick = function (event) {
// Do something with the event
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment