Java Reference
In-Depth Information
This code assigns the myButton_click() function to handle the click event for an element with an
id value of myButton element.
jQuery passes a jQuery.Event object to the function handling the event. Because of the extreme differ-
ence between the IE and W3C DOM event models, John Resig, the creator of jQuery, decided to merge
both event models into his own, which is based on the W3C event model's Event and MouseEvent
objects. That means you do not have to worry about checking for window.event or using any property
of the IE event model; the jQuery.Event object provides you the same information as window.event,
and you'll use the W3C Mouse and MouseEvent objects' properties to get at that information.
All this means is you have one unifi ed object that works across all supported browsers, to work with
events. To demonstrate, you can write something like the following code, and it'll work in every sup-
ported browser:
function myButton_click(event)
{
alert(event.target.tagName + “ clicked at X:“ + event.pageX
+ “ and Y:” + event.pageY);
}
$(“#myButton”).bind(“click”, myButton_click);
Figure 15-4 shows the results of this code in IE, and Figure 15-5 shows the results in Firefox.
Figure 15-4
Search WWH ::




Custom Search