Created
October 3, 2018 11:07
-
-
Save cladley/64ef939be4fd53777a2efdb1433f8be2 to your computer and use it in GitHub Desktop.
Event attached to a parent element and you are interested when a child is clicked
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
| // Some event attached to a parent element | |
| this.parent.addEventListener('click', this.handleItemsClick.bind(this), false); | |
| function handleItemsClick(e) { | |
| // e.currentTarget is the element that the event was attached to. this.parent here | |
| for (var target = e.target; target && target !== e.currentTarget; target = target = target.parentNode) { | |
| if (target.matches('.child-selector')) { | |
| // Do whatever | |
| break; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment