09.02.2015 Views

DOM Traversal Methods - MarkMail

DOM Traversal Methods - MarkMail

DOM Traversal Methods - MarkMail

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5<br />

<br />

<br />

Trigger<br />

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

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

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

});<br />

Now if we click on the first field, or Tab to it from another field, the message is<br />

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

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

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

});<br />

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

Triggering the focus on hidden elements causes an error in Internet<br />

Explorer. Take care to only call .focus() without parameters on<br />

elements that are visible.<br />

.blur()<br />

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

an element.<br />

.blur(handler)<br />

.blur()<br />

Parameters (First Version)<br />

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

Return Value<br />

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

Description<br />

This handler is a shortcut for .bind('blur', handler) in the first variation, and<br />

.trigger('blur') in the second.<br />

[ 119 ]

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

Saved successfully!

Ooh no, something went wrong!