Learn HTML DOM
Browser Events
5.7
Lesson

Preventing Multiple Events

In large applications, we can have many similar DOM elements on which we want to watch for an event. 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 give above. Try clicking inside the second div, but avoid the circles. The complete div changes colour, which is because we are watching for the event on the whole div. We can resolve this in the following manner: