0

I want to know how exactly event delegation works internally in JS ? People in stack overflow have already answered what is Even Delegation (What is Event Delegation) but i don't see any point or note on how it works.

How does parent node know which child node is clicked ? somewhere it should be stored right ?

Community
  • 1
  • 1
Duster
  • 31
  • 2
  • 7
  • 1
    Event delegation isn't internal to javascript, it's an approach to managing event listeners. Perhaps the [*MDN Events* article](https://developer.mozilla.org/en-US/docs/Web/API/Event) will help. – RobG Dec 05 '14 at 06:09
  • Are you looking for *event propagation*, or for [this answer](http://stackoverflow.com/a/25248515/1048572)? – Bergi Dec 05 '14 at 06:32
  • take a look at the answers of this question https://stackoverflow.com/questions/1687296/what-is-dom-event-delegation – Aminul Dec 05 '14 at 06:33

1 Answers1

1

The W3C Events Specification defines how events work. Events are dispatched on event targets, the resulting Event object has an associated target property that is the element on which the event was originally dispatched (e.g. an element that has been clicked on).

The event bubbles up the DOM and any element it comes across that has a listener for that event is called by its handler. The related event object is augmented with a currentTarget property that references the element that called the listener.

Note that not all browsers in use fully support all the above features, in particular the currentTarget property is fairly new and older IE supports event.srcElement rather than event.target

You should read the specification linked above, the MDN Event reference and related articles.

RobG
  • 124,520
  • 28
  • 153
  • 188