Binds a handler to a particular event to be executed once for each matched element.
The handler is executed only once for each element. Otherwise, the same rules as described in bind() apply. The event handler is passed an event object that you can use to prevent default behaviour. To stop both default action and event bubbling, your handler should return false.
In most cases, you can define your event handlers as anonymous functions (see first example). In cases where that is not possible, you can pass additional data as the second paramter (and the handler function as the third), see second example.
Arguments:
| type | String | |
|---|---|---|
| An event type | ||
| data (Optional) | Object | |
| Additional data passed to the event handler as event.data | ||
| fn | Function | |
A function to bind to the specified event on each of the matched elements.
function callback(eventObject) {
this; // dom element
}
| ||