JAVASCRIPT - HOW TO Add MULTIPLE EVENT LISTENERS - Javascript Source Code

JAVASCRIPT - HOW TO Add or Call Multiple Event Listeners with a Function that Allows you to Create UNLIMITED EVENT HANDLES in a Single Function Call

Home Short:

If you plan on creating at least 3 or more event handlers in Javascript, the function below can save you some time and typing.

The Javascript function below allows you to create an unlimited number of event handlers with one function call in Javascript.

For this Javascript multiple event handler function to work, you need to create 3 separate arrays ...

  1. An array of element ID's.
  2. An array of event types.
  3. An array of functions that are called when the events added to the handler are invoked.

Here is the actual function to create multiple event handlers:

Here is an example of how to use this multiple event handler function:

You can try this out for yourself with these three buttons. Right click this web page and VIEW SOURCE to see how it works.

For this example, all 4 event handlers created pointed to the same function but they can point to different functions.

S
H
A
R
E