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

Unified Diff: recipes/web/html/selectors.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, 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/selectors.html
diff --git a/recipes/web/html/selectors.html b/recipes/web/html/selectors.html
new file mode 100644
index 0000000000000000000000000000000000000000..9de507f4c009e77eee200513df884ac7306b8b94
--- /dev/null
+++ b/recipes/web/html/selectors.html
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+
+<html>
+ <body>
+ <h1>Breakfast</h1>
+ <ul>
+ <li id='first' class='mustHave'>Milk</li>
+ <li class='mustHave'>Cereal
+ <ul>
+ <li>Bran Flakes</li>
+ <li><a href='https://en.wikipedia.org/wiki/Nut_(fruit)'>Nuts</a></li>
+ </ul>
+ </li>
+ <li>Juice</li>
+ </ul>
+
+ <script type="application/dart">
+
+ import 'dart:html';
+
+ void main() {
+
+ // Find by id.
+ Element element = query('#first');
+ assert(element.id == 'first');
+ assert(element.innerHtml == 'Milk');
+
+ // Find by class.
+ List<Element> elements = queryAll('.mustHave');
+ assert(elements.length == 2);
+
+ // Find by ID and class.
+ elements = queryAll('#first, .mustHave');
+ assert(elements.length == 2);
+
+ // Find by tag.
+ elements = queryAll('li');
+ assert(elements.length == 5);
+
+ // Use hierarchical selectors.
+ elements = queryAll('li > ul > li');
+ assert(elements.first.innerHtml == "Bran Flakes");
+
+ // Use pseudo-elements.
+ element = query('li:nth-child(1)');
+ assert(element.innerHtml == 'Milk');
+
+ // Find by attribute.
+ elements = queryAll('[href *= Nut]');
+ assert(elements.length == 1);
+
+ }
+ </script>
+ <script src="packages/browser/dart.js"></script>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698