Skip to content

Instantly share code, notes, and snippets.

@colabottles
Created January 7, 2020 02:24
Show Gist options
  • Select an option

  • Save colabottles/ccb61b350f879d4c994bfb56592d39f0 to your computer and use it in GitHub Desktop.

Select an option

Save colabottles/ccb61b350f879d4c994bfb56592d39f0 to your computer and use it in GitHub Desktop.
Listening for events and user interactions // source https://jsbin.com/wabamo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Listening for events and user interactions</title>
</head>
<body>
<button class="this-button" id="click-me-once">Click Me!</button>
<script id="jsbin-javascript">
var btn = document.querySelector('#click-me-once');
btn.addEventListener('click', function (event) {
console.log(event); // The event details
console.log(event.target); // The clicked element
}, false);
</script>
<script id="jsbin-source-javascript" type="text/javascript">var btn = document.querySelector('#click-me-once');
btn.addEventListener('click', function (event) {
console.log(event); // The event details
console.log(event.target); // The clicked element
}, false);
</script></body>
</html>
var btn = document.querySelector('#click-me-once');
btn.addEventListener('click', function (event) {
console.log(event); // The event details
console.log(event.target); // The clicked element
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment