Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(823)

Side by Side Diff: recipes/web/html/traversing_from_current_position.html

Issue 14109034: Recipes for using CSS Selectors with dart:html (Closed) Base URL: https://github.com/dart-lang/cookbook.git@master
Patch Set: Changes based on Kathy's comments. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « recipes/web/html/selectors_hierarchy.html ('k') | scoped_selectors.asciidoc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!DOCTYPE html>
2
3 <html>
4 <ol>
5 <li>Head</li>
6 <li>Shoulders</li>
7 <li>Knees</li>
8 <li>Toes</li>
9 </ol>
10
11 <body>
12 <script type="application/dart">
13 import 'dart:html';
14
15 List<Element> nextSiblings(item) {
16 Element nextElement = item.nextElementSibling;
17 return item.parent.children.skipWhile((i) => i != nextElement).toList();
18 }
19
20 List<Element> previousSiblings(item) {
21 return item.parent.children.takeWhile((i) => i != item).toList();
22 }
23
24 void main() {
25 LIElement knees = query('ol > li:nth-child(3)');
26
27 // Parent.
28 assert(knees.parent.tagName == 'OL');
29 assert(knees.parent.children.length == 4);
30
31 // Immediate neighbors.
32 assert(knees.nextElementSibling.text == 'Toes');
33 assert(knees.previousElementSibling.text == 'Shoulders');
34
35 // Siblings.
36 List<Element> prev = previousSiblings(knees);
37 assert(prev.first.text == 'Head');
38 assert(prev.last.text == 'Shoulders');
39 assert(nextSiblings(knees).first.text == 'Toes');
40 }
41 </script>
42 <script src="packages/browser/dart.js"></script>
43 </body>
44 </html>
OLDNEW
« no previous file with comments | « recipes/web/html/selectors_hierarchy.html ('k') | scoped_selectors.asciidoc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698