Events and event handling are an important part of client-side development. Frequently we are tasked with changing their behaviour and part of that process involves locating which methods handle which events. From jQuery version 1.7 onwards, the preferred method of attaching an event handler is .on() http://api.jquery.com/on/ , and its companion methods .on() and .off(). The .on() is a very flexible method because it covers all the capabilities of .live() and .bind() in a single method.
The following is an example of .on() can attach an event handler directly to a dom element:
This is the equivalent of either of:
The Event Object
jQuery hides implementation differences among browsers by defining its own Event object . When a jQuery event handler is invoked, it is always passed a jQuery Event object as its first argument. This object holds additional information about the event. The event object is guaranteed to be passed to the event handler . Most properties from the original event are copied over and normalized to the new event object. It's often helpful to use the extra information contained in the event object passed to the event handler for more control. To become familiar with the event object, use this code to inspect it in your browser console after you click on a < div > in the page.