Adding Event Handlers in jQuery

$("div").on("click", "span", {name:"Brad", number:7},   function(e){     (event handler code here) }):

Events are added in jQuery using the .on(events,[,selector][,data]handler(eventObject) method. This method accepts one or more event types such as those listed in Table 6.1 as the first argument.

The optional selector value defines the descendant elements that trigger the event. Any descendant elements that match the selector also trigger the event.

The data object is anything that you want to pass to the event handler in the event.data attribute. Typically, this is either a single value or a JavaScript object. However, anything is accepted.

The handler function is the function ...

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.