05.01.2013 Views

hide - Understanding jQuery

hide - Understanding jQuery

hide - Understanding jQuery

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Event Capture<br />

Even though the image was clicked, the image element is not the first to actually receive the<br />

first event. Instead, the event is first processed by the document. In other words, the document<br />

captures the event first. It then passes it to first div element, then to the second, and finally the<br />

event arrives at its target, which is the image element. Each of the “ancestor” elements of the<br />

target (img) receive the event and pass it on until the target element is reached. The target element<br />

is defined by the original element that receives action first.<br />

Event Bubbling<br />

Bubbling is the reverse of capture. In this case, the target element that receives the action, such<br />

as a mouse click, will process the event first using its event handler. Then, the event “bubbles”<br />

up the DOM ancestor tree, all the way to document. Sort of like the bubbles in a glass of champagne.<br />

Both event capture and bubbling happen behind the scenes, and many developers are not<br />

aware that this is even happening while working with <strong>jQuery</strong> event functions. But this knowledge<br />

is important because it is often the source of confusion when it comes to writing complex<br />

script programs.<br />

List of All <strong>jQuery</strong> Events<br />

Your productivity as a <strong>jQuery</strong> developer will depend on how many event names you can recall<br />

from your memory. The more events you commit to your memory, the less time you will<br />

spend looking them up. Below is a table containing some of the <strong>jQuery</strong> events. You can see a<br />

list of all <strong>jQuery</strong> events by going to the link below the table. I just didn’t want to clutter this email.<br />

The link redirects to a page that can be printed out for your reference.<br />

Event function Event description<br />

.bind()<br />

.blur()<br />

.change()<br />

.click()<br />

.dblclick()<br />

.delegate()<br />

.die()<br />

.error()<br />

.focus()<br />

.focusin()<br />

.focusout()<br />

.hover()<br />

.on() and off()<br />

Attach a function to an arbitrary event of your choice.<br />

Attach “focus left a selected element” event.<br />

Value of the selected input element has changed.<br />

The selected element(s) has been clicked.<br />

The selected element(s) has been double clicked.<br />

Old function for .on(), use. on() instead.<br />

Remove all events that were attached with .live()<br />

Bind a handler to the “error” Javascript event<br />

The selected element(s) received cursor focus<br />

Detect focus of an input element nested inside an arbitrary parent (the selection)<br />

Detect the loss of cursor focus of an input element nested inside a parent.<br />

Mouse enters the area of an element.<br />

New function equivalents to use instead of .bind() and .unbind()<br />

For the full list of <strong>jQuery</strong> events refer to this page:<br />

www.authenticsociety.com/jquery/list-all-jquery-events.html<br />

98

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!