02.06.2013 Views

DOM Traversal Methods

DOM Traversal Methods

DOM Traversal Methods

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.

<strong>DOM</strong> <strong>Traversal</strong> <strong>Methods</strong><br />

Cause there's a train coming into the station<br />

But it's heading for a new destination<br />

—Devo,<br />

"It Doesn't Matter to Me"<br />

In addition to the selector expressions described in Chapter 2, jQuery has a variety<br />

of <strong>DOM</strong> traversal methods to help us select elements in a document. These methods<br />

offer a great deal of flexibility, even allowing us to act upon multiple sets of elements<br />

in a single chain, like so:<br />

$('div.section > p').addClass('lit').lt(1).addClass('profound');<br />

At times the choice between a selector expression and a corresponding <strong>DOM</strong><br />

traversal method is simply a matter of taste, but there is no doubt that the combined<br />

set of expressions and methods makes for an extremely powerful toolset for getting<br />

anything we want.<br />

As of jQuery 1.1, <strong>DOM</strong> traversal methods do not modify the jQuery object they are<br />

sent to. Instead, a new jQuery object is constructed, which contains a reference to the<br />

original object. The original objec t can be retrieved with the .end method.<br />

The jQuery Factory Function<br />

The following function underpins the entire jQuery library as it allows us to create<br />

the jQuery objects that all of the other methods are attached to.

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

Saved successfully!

Ooh no, something went wrong!