jQuery in Action

Managing the wrapped element set
43
matches all elements on the page and then returns a set containing all but the
first four elements.
And we're not done yet! jQuery also gives us the ability to obtain subsets of a
wrapped set, based on the relationship of the wrapped items with other elements
in the
DOM
. Let's see how.
2.3.4 Getting wrapped sets using relationships
jQuery allows us to get new wrapped sets from an existing set, based on the hier-
archical relationships of the wrapped element to the other elements within the
HTML
DOM
. Note that these methods operate in a slightly different manner than
most earlier methods in this section that modify the wrapped set upon which they
are called. Like the
slice()
method, the methods we'll see in this section return a
new wrapped set, leaving the original set unchanged.
Table 2.4 shows these methods and their descriptions. Each of these methods
accepts an optional selector expression that any selected elements must match. If
no such selector parameter is passed, all eligible elements are selected.
These methods give us a large degree of freedom to select elements from the
DOM
, based on relationships to the other
DOM
elements. But we're still not done.
Let's see how jQuery deals further with wrapped sets.
Table 2.4 Methods to obtain new wrapped set based on relationships
Method
Description
children()
Returns a wrapped set consisting of all unique children of the wrapped elements.
contents()
Returns a wrapped set of the contents of the elements, which may include text nodes, in
the wrapped set. (Frequently used to obtain the contents of <iframe> elements.)
next()
Returns a wrapped set consisting of all unique next siblings of the wrapped elements.
nextAll()
Returns a wrapped set containing all the following siblings of the wrapped elements.
parent()
Returns a wrapped set consisting of the unique direct parents of all wrapped elements.
parents()
Returns a wrapped set consisting of the unique ancestors of all wrapped elements. This
includes the direct parents as well as the remaining ancestors all the way up to, but not
including, the document root.
prev()
Returns a wrapped set consisting of all unique previous siblings of the wrapped elements.
prevAll()
Returns a wrapped set containing all the previous siblings of the wrapped elements.
siblings()
Returns a wrapped set consisting of all unique siblings of the wrapped elements.


Другие страницы

 
Cкачать книги бесплатно без регистрации в электронном виде (pdf, chm, txt).Вы можете читать книги онлайн на нашем сайте литературного портала книг.Большая подборка учебников, пособий, интересных книг.Электронные книги на английском языке скачать бесплатно без смс.