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

Unified Diff: recipes/web/html/selectors_attribute.html

Issue 14109034: Recipes for using CSS Selectors with dart:html (Closed) Base URL: https://github.com/dart-lang/cookbook.git@master
Patch Set: Incorporated changes recommended by Seth 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_attribute.html
diff --git a/recipes/web/html/selectors_attribute.html b/recipes/web/html/selectors_attribute.html
new file mode 100644
index 0000000000000000000000000000000000000000..45972f7c1c204f597d52512704c1c26364f65859
--- /dev/null
+++ b/recipes/web/html/selectors_attribute.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+
+<html>
+ <head>
+ <title>selectors_attribute</title>
+ </head>
+
+ <body>
+ <p>
+ <a href="example.html" hreflang="en">Some text</a><br>
+ <a href="example.html" hreflang="en-UK">Some other text</a><br>
+ <a href="example.html" hreflang="english">will not be outlined</a><br>
+ </p>
+
+ <script type="application/dart">
+
+ import 'dart:html';
+
+ List<Element> elements;
+ void main() {
+
+ // Match starts with string, or until '-'.
+ List<Element> elements = queryAll(r'a[hreflang |= "en"]');
+ assert(elements.length == 2);
+
+ // Match contains string.
+ elements = queryAll(r'a[hreflang *= "en"]');
+ assert(elements.length == 3);
+
+ // Whole word match.
+ elements = queryAll(r'a[hreflang ~= "en"]');
+ assert(elements.length == 1);
+
+ // Match ends with string. Won't work without a raw string or \$.
+ elements = queryAll(r'a[hreflang $= "ish"]');
+ assert(elements.length == 1);
+
+ // Match begins with string.
+ elements = queryAll('a[hreflang ^= "en"]');
+ assert(elements.length == 3);
+
+ // Exact match.
+ elements = queryAll(r'a[hreflang = "english"]');
+ assert(elements.length == 1);
+
+ // Exact negative match. Cannot use !=.
+ elements = queryAll(r'a:not([hreflang = "english"])');
+ assert(elements.length == 2);
+
+ // Has attribute.
+ elements = queryAll('a[hreflang]');
+ assert(elements.length == 3);
+
+ // Has multiple attributes.
+ elements = queryAll('a[hreflang][href]');
+ assert(elements.length == 3);
+ }
+
+ </script>
+ <script src="packages/browser/dart.js"></script>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698