Skip to content

Instantly share code, notes, and snippets.

@cladley
Created October 3, 2018 11:07
Show Gist options
  • Select an option

  • Save cladley/64ef939be4fd53777a2efdb1433f8be2 to your computer and use it in GitHub Desktop.

Select an option

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
// 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