Created
July 30, 2017 20:12
-
-
Save prof3ssorSt3v3/bb25544df87b1924fc59597fd1e69723 to your computer and use it in GitHub Desktop.
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
// Event Bubbling and Propagation | |
// element.addEventListener( type, func, useCapture); | |
let m = document.getElementById('m'); | |
let d = document.getElementById('d'); | |
let p = document.getElementById('p'); | |
let s = document.getElementById('s'); | |
let log = console.log; | |
let highlight = (ev)=>{ | |
//add CSS class "gold" to the clicked element | |
ev.stopPropagation(); | |
let target = ev.currentTarget; | |
target.className = 'gold'; | |
reset(target); | |
} | |
let reset = (_element)=>{ | |
setTimeout(()=>{ | |
_element.className = ''; | |
}, 2000); | |
} | |
d.addEventListener('click', (ev)=>{ | |
ev.stopImmediatePropagation(); | |
log('Hi I\'m a DIV'); | |
}); | |
[m,d,p,s].forEach((element)=>{ | |
element.addEventListener('click', highlight); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment