Skip to content

Instantly share code, notes, and snippets.

@richardgill
Created August 25, 2017 10:29
Show Gist options
  • Save richardgill/89559f92c0a3bf82b4b23ca8125eefb3 to your computer and use it in GitHub Desktop.
Save richardgill/89559f92c0a3bf82b4b23ca8125eefb3 to your computer and use it in GitHub Desktop.
Event propogation example
<div id=1 onClick=(e) => {
  console.log(1)
}>
  <div id=2 onClick=(e) => {
    console.log(2)
  }>
   2
  </div>
  1
</div>

If you click on div 2.

prints:

2
1
<div id=1 onClick=(e) => {
  console.log(1)
}>
  <div id=2 onClick=(e) => {
    console.log(2)
    e.preventDefault()
  }>
   2
  </div>
  1
</div>

If you click on div 2.

prints:

2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment