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

Unified 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: Made changes based on reviewers' comments. Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: recipes/web/html/traversing_from_current_position.html
diff --git a/recipes/web/html/traversing_from_current_position.html b/recipes/web/html/traversing_from_current_position.html
new file mode 100644
index 0000000000000000000000000000000000000000..7f2990783af483031d40e47f92c55e1078802364
--- /dev/null
+++ b/recipes/web/html/traversing_from_current_position.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+
+<html>
+ <ol>
+ <li>Head</li>
+ <li>Shoulders</li>
+ <li>Knees</li>
+ <li>Toes</li>
+ </ol>
+
+ <body>
+ <script type="application/dart">
+ import 'dart:html';
+
+ List<Element> nextSiblings(item) {
+ Element nextElement = item.nextElementSibling;
+ return item.parent.children.skipWhile((i) => i != nextElement).toList();
+ }
+
+ List<Element> previousSiblings(item) {
+ return item.parent.children.takeWhile((i) => i != item).toList();
+ }
+
+ void main() {
+ LIElement knees = query('ol > li:nth-child(3)');
+
+ // Parent.
+ assert(knees.parent.tagName == 'OL');
+ assert(knees.parent.children.length == 4);
+
+ // Immediate neighbors.
+ assert(knees.nextElementSibling.text == 'Toes');
+ assert(knees.previousElementSibling.text == 'Shoulders');
+
+ // Siblings.
+ List<Element> prev = previousSiblings(knees);
+ assert(prev.first.text == 'Head');
+ assert(prev.last.text == 'Shoulders');
+ assert(nextSiblings(knees).first.text == 'Toes');
+ }
+ </script>
+ <script src="packages/browser/dart.js"></script>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698