OLD | NEW |
---|---|
(Empty) | |
1 === Using CSS selectors within a limited scope | |
2 | |
3 ==== Problem | |
4 | |
5 You have a handle on a selected DOM element and want to search for other | |
Kathy Walrath
2013/04/29 21:17:02
handle on -> handle to
(Now I'm getting confused
Andrei Mouravski
2013/04/29 21:21:44
A handle?
Andrei Mouravski
2013/04/29 21:21:44
You want to find an element that is a child of a s
shailentuli
2013/04/30 02:59:31
Done.
shailentuli
2013/04/30 02:59:31
Using Kathy's suggestion, above.
| |
6 elements within it. | |
7 | |
8 ==== Solution | |
9 | |
10 Use the `query()` and `queryAll()` functions as methods of the currently | |
Kathy Walrath
2013/04/29 21:17:02
I found this a bit confusing and wasn't sure it wa
Andrei Mouravski
2013/04/29 21:21:44
"As methods of the..." is weird.
Call the `query`
shailentuli
2013/04/30 02:59:31
Done.
shailentuli
2013/04/30 02:59:31
Done.
| |
11 selected element. This restricts the scope of the query to the currently | |
Kathy Walrath
2013/04/29 21:17:02
"This" -> Using one of these methods restricts the
shailentuli
2013/04/30 02:59:31
Done.
| |
12 selected element's descendants: | |
13 | |
14 -------------------------------------------------------------------------------- | |
15 currentlySelectedElement.query(cssSelector); | |
Kathy Walrath
2013/04/29 21:17:02
currentlySelectedElement -> containerElement
(glo
shailentuli
2013/04/30 02:59:31
Done.
| |
16 currentlySelectedElement.queryAll(cssSelector); | |
17 -------------------------------------------------------------------------------- | |
18 | |
19 ==== Examples | |
20 | |
21 Consider the following table of user records: | |
22 | |
23 -------------------------------------------------------------------------------- | |
24 <table> | |
25 <tr><td>Jose</td><td class='status'>Accepted</td></tr> | |
26 <tr><td>Marie</td><td class='status'>Accepted</td></tr> | |
27 <tr><td>Kwame</td><td class='status'>Accepted</td></tr> | |
28 <tr><td>Rohan</td><td class='status'>Accepted</td></tr> | |
29 </table> | |
Andrei Mouravski
2013/04/29 21:21:44
Have two tables, or maybe they can be ULs and give
shailentuli
2013/04/30 02:59:31
WITTIEST CL COMMENT EVER. But, no, alas, Donny wil
shailentuli
2013/04/30 02:59:31
Done.
| |
30 -------------------------------------------------------------------------------- | |
31 | |
32 The following code attaches an event handler to each <tr>. When a <tr> is | |
33 clicked, the text within the matching descendant <td> toggles: | |
34 | |
35 -------------------------------------------------------------------------------- | |
36 queryAll('tr').forEach((element) { | |
Kathy Walrath
2013/04/29 21:17:02
I was initially a bit confused when I saw this bec
shailentuli
2013/04/30 02:59:31
Yup, it is a bit confusing. Adding a note at the e
| |
37 element.onClick.listen((event) { | |
38 var record = event.currentTarget.query('.status'); | |
39 record.innerHtml = record.innerHtml == 'Accepted' ? 'Declined' : 'Accepted'; | |
40 }); | |
41 }); | |
42 -------------------------------------------------------------------------------- | |
43 | |
44 Because of the scoped query, non-descendant <td>s with the '.status' class are | |
Kathy Walrath
2013/04/29 21:17:02
Could be clearer. How about:
Because the query()
Andrei Mouravski
2013/04/29 21:21:44
"Because the query is scoped to whatever, ..."
shailentuli
2013/04/30 02:59:31
Done.
shailentuli
2013/04/30 02:59:31
Done.
| |
45 not affected. | |
46 | |
47 | |
OLD | NEW |