02.06.2013 Views

DOM Traversal Methods

DOM Traversal Methods

DOM Traversal Methods

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 <strong>Methods</strong><br />

The blur event is sent to an element when it loses focus. Originally, this event was<br />

only applicable to form elements, such as . In recent browsers, the domain of<br />

the event has been extended to include all element types. An element can lose focus<br />

via keyboard commands, such as the Tab key, or by mouse clicks elsewhere on<br />

the page.<br />

For example, consider the HTML:<br />

<br />

<br />

<br />

<br />

Trigger<br />

The event handler can be bound to the first input field:<br />

$('.target').blur(function() {<br />

$(this).log('Blur event was triggered.');<br />

});<br />

Now if we click on the first field, then click or tab away, the message is displayed.<br />

We can trigger the event when the button is clicked:<br />

$('.trigger').click(function() {<br />

$('.target').blur();<br />

});<br />

After this code executes, clicking the Trigger button will also display the message.<br />

.change()<br />

Binds an event handler to the change JavaScript event, or triggers that event on<br />

an element.<br />

.change(handler)<br />

.change()<br />

Parameters (First Version)<br />

•<br />

handler: A function to execute each time the event is triggered<br />

Return Value<br />

The jQuery object, for chaining purposes.<br />

[ 120 ]

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

Saved successfully!

Ooh no, something went wrong!