Last active
August 29, 2015 14:17
-
-
Save mixtmeta/1d8ef89449df51b50063 to your computer and use it in GitHub Desktop.
Javascript Events example
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
| #outer { | |
| width: 500px; | |
| height: 500px; | |
| background-color: green; | |
| } | |
| #inner { | |
| width: 150px; | |
| height: 150px; | |
| background-color: red; | |
| } |
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>EVents App</title> | |
| <link href="./app.css" rel="stylesheet"> | |
| </head> | |
| <body> | |
| <div id="outer"> | |
| <div id="inner"></div> | |
| </div> | |
| </body> | |
| <script src="./app.js"></script> | |
| </html> |
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
| // var outerEl = document.getElementById('outer'); | |
| // var innerEl = document.getElementById('inner'); | |
| // console.log(outerEl) | |
| // console.log(innerEl) | |
| function queryId(id) { | |
| return document.getElementById(id); | |
| } | |
| var query = { | |
| id: queryId | |
| } | |
| var outerEl = query.id('outer'); | |
| var innerEl = query.id('inner'); | |
| function alertClicked(event) { | |
| console.log(event); | |
| } | |
| function stopBubbling(event) { | |
| event.stopPropagation(); | |
| alertClicked(event); | |
| } | |
| outer.addEventListener('click', alertClicked); | |
| inner.addEventListener('click', stopBubbling); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment