Index: scoped_selectors.asciidoc |
diff --git a/scoped_selectors.asciidoc b/scoped_selectors.asciidoc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..28790f3569918323fa5c18897ee34f2de64a7fc3 |
--- /dev/null |
+++ b/scoped_selectors.asciidoc |
@@ -0,0 +1,47 @@ |
+=== Using CSS selectors within a limited scope |
+ |
+==== Problem |
+ |
+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.
|
+elements within it. |
+ |
+==== Solution |
+ |
+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.
|
+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.
|
+selected element's descendants: |
+ |
+-------------------------------------------------------------------------------- |
+currentlySelectedElement.query(cssSelector); |
Kathy Walrath
2013/04/29 21:17:02
currentlySelectedElement -> containerElement
(glo
shailentuli
2013/04/30 02:59:31
Done.
|
+currentlySelectedElement.queryAll(cssSelector); |
+-------------------------------------------------------------------------------- |
+ |
+==== Examples |
+ |
+Consider the following table of user records: |
+ |
+-------------------------------------------------------------------------------- |
+<table> |
+ <tr><td>Jose</td><td class='status'>Accepted</td></tr> |
+ <tr><td>Marie</td><td class='status'>Accepted</td></tr> |
+ <tr><td>Kwame</td><td class='status'>Accepted</td></tr> |
+ <tr><td>Rohan</td><td class='status'>Accepted</td></tr> |
+</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.
|
+-------------------------------------------------------------------------------- |
+ |
+The following code attaches an event handler to each <tr>. When a <tr> is |
+clicked, the text within the matching descendant <td> toggles: |
+ |
+-------------------------------------------------------------------------------- |
+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
|
+ element.onClick.listen((event) { |
+ var record = event.currentTarget.query('.status'); |
+ record.innerHtml = record.innerHtml == 'Accepted' ? 'Declined' : 'Accepted'; |
+ }); |
+}); |
+-------------------------------------------------------------------------------- |
+ |
+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.
|
+not affected. |
+ |
+ |