Skip to content

Commit 0ef74d7

Browse files
committed
add closest, and cleaned up some wording
1 parent 8263c12 commit 0ef74d7

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

content/jquery-basics/traversing.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title : "Traversing"
55
---
66
## Traversing
77

8-
Once you have made an intial selection with jQuery, you may want to traverse a little deeper into what you just selected. Traversing can be broken down into three basic parts: parents, children and sibilings. jQuery has an abundance of easy to use methods for all these parts. You will notice that each of these methods can optionaly be passed another selector or selection in order to refine your selection even more.
8+
Once you have made an intial selection with jQuery, you may want to traverse a little deeper into what you just selected. Traversing can be broken down into three basic parts: parents, children and sibilings. jQuery has an abundance of easy to use methods for all these parts. You will notice that each of these methods can optionaly be passed string selector and some can also take another jQuery object in order to filter your selection down. Be sure to pay attention and refer to the API docs to know what all variation of arguments you have available.
99

1010

1111
### Parents
@@ -18,24 +18,29 @@ Selecting an element's direct parent
1818
$('#myList').parent();
1919
</div>
2020
<div class="example" markdown="1">
21-
Selecting all the parents of an element which match a given selector
21+
Selecting all the parents of an element that match a given selector
2222

23-
$('#myList').parents('div');
23+
$('#myList').parents('div.section');
2424
</div>
2525
<div class="example" markdown="1">
2626
Selecting all the parents of an element up to, but *not including* the selector
2727

28-
$('#myList').parentsUntil('div');
28+
var section = $('div.section');
29+
$('#myList').parentsUntil(section);
2930
</div>
31+
<div class="example" markdown="1">
32+
Selecting the closest parent, note that only one parent will be selected.
3033

34+
$('#myList').closest('#navigation');
35+
</div>
3136
### Children
3237

33-
There are only 2 methods for finding children elements from a selection: `$.fn.children` and `$.fn.find`. The difference between these methods lies in how far into the child structure the selection is made. `$.fn.children` only operates on direct child nodes, while `$.fn.find` can traverse recursively into children, and children of those children, etc.
38+
There are only 2 methods for finding child elements from a selection: `$.fn.children` and `$.fn.find`. The difference between these methods lies in how far into the child structure the selection is made. `$.fn.children` only operates on direct child nodes, while `$.fn.find` can traverse recursively into children, and children of those children, etc.
3439

3540
<div class="example" markdown="1">
3641
Selecting an element's direct children
3742

38-
$('#myList').children();
43+
$('#myList').children('li');
3944
</div>
4045
<div class="example" markdown="1">
4146
Finding all the links within a selection that match the selector

0 commit comments

Comments
 (0)