O'Reilly logo

Moodle JavaScript Cookbook by Alastair Hole

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing event delegation

So far we have looked at a range of methods for registering single events to single elements. These techniques are very useful but it becomes inefficient and laborious when we wish to register events for multiple elements.

If we take the example of a navigation control in the form of a list of links, we could implement a click event for each link by manually registering the event against the ID of the element. While this may be fine for a handful of links, as soon as the list starts to get larger it becomes very cumbersome to manage these events. The more links there are, the more it becomes prone to mistakes and bugs. Would you want to write (and manage) code to register click events to 50 links by hand if you didn't ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required