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

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: Removed unwanted file. 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
OLDNEW
(Empty)
1 <!DOCTYPE html>
2
3 <html>
4 <ul>
5 <li>Head</li>
6 <li>Shoulders</li>
7 <li>Knees</li>
8 <li>Toes</li>
9 </ul>
10
11 <body>
12 <script type="application/dart">
13 import 'dart:html';
14
15 nextSiblings(item) {
16 Element nextElement = item.nextElementSibling;
17 return item.parent.children.skipWhile((i) => i != nextElement).toList();
18 }
19
20 previousSiblings(item) {
21 return item.parent.children.takeWhile((i) => i != item).toList();
22 }
23
24 List prevAll(item) {
25 var results = [];
26 var children = item.parent.children;
27
28 for (var i = 0; i < children.length; i++) {
29 if (children[i] == item) break;
30 results.add(children[i]);
31 }
32 return results;
33 }
34
35 void main() {
36 LIElement knees = query('ul > li:nth-child(3)');
37 assert(knees.nextElementSibling.innerHtml == 'Toes');
38 assert(knees.previousElementSibling.innerHtml == 'Shoulders');
39 assert(knees.parent.tagName == 'UL');
40 assert(knees.parent.children.length == 4);
41 List<Element> prev = previousSiblings(knees);
42 assert(prev.first.innerHtml == 'Head');
43 assert(prev.last.innerHtml == 'Shoulders');
44 assert(nextSiblings(knees).first.innerHtml == 'Toes');
45 }
46 </script>
47 <script src="packages/browser/dart.js"></script>
48 </body>
49 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698