In large applications, we can have
many similar DOM elements on which
we want to watch for an event. Instead
of following this approach, and creating
multiple event listeners, it makes sense
to simply watch for the event on their parent
DOM element.
Look at the example given below:
There is a problem with the second method
given above. Try clicking inside the second div,
but avoid the circles. The complete div
becomes
green. Why did this happen?
This happens because we are watching for the
click event on the whole div
. We can resolve this by
adding in a condition that ensures that changes only
get applied when we click on a circle. Look at the example
given below: