O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

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

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 ...

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