You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/jquery-basics/traversing.md
+11-6
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ title : "Traversing"
5
5
---
6
6
## Traversing
7
7
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.
9
9
10
10
11
11
### Parents
@@ -18,24 +18,29 @@ Selecting an element's direct parent
18
18
$('#myList').parent();
19
19
</div>
20
20
<divclass="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
22
22
23
-
$('#myList').parents('div');
23
+
$('#myList').parents('div.section');
24
24
</div>
25
25
<divclass="example"markdown="1">
26
26
Selecting all the parents of an element up to, but *not including* the selector
27
27
28
-
$('#myList').parentsUntil('div');
28
+
var section = $('div.section');
29
+
$('#myList').parentsUntil(section);
29
30
</div>
31
+
<divclass="example"markdown="1">
32
+
Selecting the closest parent, note that only one parent will be selected.
30
33
34
+
$('#myList').closest('#navigation');
35
+
</div>
31
36
### Children
32
37
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.
34
39
35
40
<divclass="example"markdown="1">
36
41
Selecting an element's direct children
37
42
38
-
$('#myList').children();
43
+
$('#myList').children('li');
39
44
</div>
40
45
<divclass="example"markdown="1">
41
46
Finding all the links within a selection that match the selector
0 commit comments