Parents
The methods for finding the parents from a selection include .parent()
, .parents()
, .parentsUntil()
, and .closest()
.
1
2
3
4
5
6
7
8
9
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
|
Children
The methods for finding child elements from a selection include .children()
and .find()
. The difference between these methods lies in how far into the child structure the selection is made. .children()
only operates on direct child nodes, while .find()
can traverse recursively into children, children of those children, and so on.
1
2
3
4
5
6
7
8
9
|
|
Siblings
The rest of the traversal methods within jQuery all deal with finding sibling selections. There are a few basic methods as far as the direction of traversal is concerned. You can find previous elements with .prev()
, next elements with .next()
, and both with .siblings()
. There are also a few other methods that build onto these basic methods: .nextAll()
, .nextUntil()
, .prevAll()
and .prevUntil()
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
|
Use .siblings()
to select all siblings:
1
2
3
4
5
6
7
|
|
Be cautious when traversing long distances in documents – complex traversal makes it imperative that the document's structure remain the same, which is difficult to guarantee even if you're the one creating the whole application from server to client. One- or two-step traversal is fine, but it's best to avoid traversals that go from one container to another.
source: http://learn.jquery.com/using-jquery-core/traversing/