3 <title>testing dojo.query()</title>
4 <style type="text/css">
5 @import "../../resources/dojo.css";
7 <script type="text/javascript" src="../../dojo.js"
8 djConfig="isDebug: true, debugAtAllCosts: false, noFirebugLite: true"></script>
9 <script type="text/javascript" src="../../../util/doh/runner.js"></script>
10 <script type="text/javascript">
11 dojo.require("doh.runner");
12 dojo.require("dojox.data.dom");
13 dojo.addOnLoad(function(){
16 // basic sanity checks
17 "doh.is(4, (dojo.query('h3')).length);",
18 "doh.is(1, (dojo.query('h1:first-child')).length);",
19 "doh.is(2, (dojo.query('h3:first-child')).length);",
20 "doh.is(1, (dojo.query('#t')).length);",
21 "doh.is(1, (dojo.query('#bug')).length);",
22 "doh.is(4, (dojo.query('#t h3')).length);",
23 "doh.is(1, (dojo.query('div#t')).length);",
24 "doh.is(4, (dojo.query('div#t h3')).length);",
25 "doh.is(0, (dojo.query('span#t')).length);",
26 "doh.is(1, (dojo.query('#t div > h3')).length);",
27 "doh.is(2, (dojo.query('.foo')).length);",
28 "doh.is(1, (dojo.query('.foo.bar')).length);",
29 "doh.is(2, (dojo.query('.baz')).length);",
30 "doh.is(3, (dojo.query('#t > h3')).length);",
31 // syntactic equivalents
32 "doh.is(12, (dojo.query('#t > *')).length);",
33 "doh.is(12, (dojo.query('#t >')).length);",
34 "doh.is(3, (dojo.query('.foo >')).length);",
35 "doh.is(3, (dojo.query('.foo > *')).length);",
37 "doh.is(3, (dojo.query('> *', 'container')).length);",
38 "doh.is(3, (dojo.query('> h3', 't')).length);",
40 "doh.is(2, (dojo.query('.foo, .bar')).length);",
41 "doh.is(2, (dojo.query('.foo,.bar')).length);",
42 // multiple class attribute
43 "doh.is(1, (dojo.query('.foo.bar')).length);",
44 "doh.is(2, (dojo.query('.foo')).length);",
45 "doh.is(2, (dojo.query('.baz')).length);",
47 "doh.is(1, (dojo.query('span.baz')).length);",
48 "doh.is(1, (dojo.query('sPaN.baz')).length);",
49 "doh.is(1, (dojo.query('SPAN.baz')).length);",
50 "doh.is(1, (dojo.query('[class = \"foo bar\"]')).length);",
51 "doh.is(2, (dojo.query('[foo~=\"bar\"]')).length);",
52 "doh.is(2, (dojo.query('[ foo ~= \"bar\" ]')).length);",
53 // "t.is(0, (dojo.query('[ foo ~= \"\\'bar\\'\" ]')).length);",
54 "doh.is(3, (dojo.query('[foo]')).length);",
55 "doh.is(1, (dojo.query('[foo$=\"thud\"]')).length);",
56 "doh.is(1, (dojo.query('[foo$=thud]')).length);",
57 "doh.is(1, (dojo.query('[foo$=\"thudish\"]')).length);",
58 "doh.is(1, (dojo.query('#t [foo$=thud]')).length);",
59 "doh.is(1, (dojo.query('#t [ title $= thud ]')).length);",
60 "doh.is(0, (dojo.query('#t span[ title $= thud ]')).length);",
61 "doh.is(1, (dojo.query('[foo|=\"bar\"]')).length);",
62 "doh.is(1, (dojo.query('[foo|=\"bar-baz\"]')).length);",
63 "doh.is(0, (dojo.query('[foo|=\"baz\"]')).length);",
64 "doh.is(dojo.byId('_foo'), dojo.query('.foo:nth-child(2)')[0]);",
65 "doh.is(dojo.query('style')[0], dojo.query(':nth-child(2)')[0]);",
66 // descendant selectors
67 "doh.is(3, dojo.query('>', 'container').length);",
68 "doh.is(3, dojo.query('> *', 'container').length);",
69 "doh.is(2, dojo.query('> [qux]', 'container').length);",
70 "doh.is('child1', dojo.query('> [qux]', 'container')[0].id);",
71 "doh.is('child3', dojo.query('> [qux]', 'container')[1].id);",
72 "doh.is(3, dojo.query('>', 'container').length);",
73 "doh.is(3, dojo.query('> *', 'container').length);",
74 "doh.is('passed', dojo.query('#bug')[0].value);",
76 "doh.is(1, dojo.query('+', 'container').length);",
77 "doh.is(3, dojo.query('~', 'container').length);",
78 "doh.is(1, (dojo.query('.foo + span')).length);",
79 "doh.is(4, (dojo.query('.foo ~ span')).length);",
80 "doh.is(1, (dojo.query('#foo ~ *')).length);",
81 "doh.is(1, (dojo.query('#foo ~')).length);",
82 // sub-selector parsing
83 "doh.is(1, dojo.query('#t span.foo:not(span:first-child)').length);",
84 "doh.is(1, dojo.query('#t span.foo:not(:first-child)').length);",
87 "doh.is(2, dojo.query('#t > h3:nth-child(odd)').length);",
88 "doh.is(3, dojo.query('#t h3:nth-child(odd)').length);",
89 "doh.is(3, dojo.query('#t h3:nth-child(2n+1)').length);",
90 "doh.is(1, dojo.query('#t h3:nth-child(even)').length);",
91 "doh.is(1, dojo.query('#t h3:nth-child(2n)').length);",
92 "doh.is(0, dojo.query('#t h3:nth-child(2n+3)').length);",
93 "doh.is(2, dojo.query('#t h3:nth-child(1)').length);",
94 "doh.is(1, dojo.query('#t > h3:nth-child(1)').length);",
95 "doh.is(3, dojo.query('#t :nth-child(3)').length);",
96 "doh.is(0, dojo.query('#t > div:nth-child(1)').length);",
97 "doh.is(7, dojo.query('#t span').length);",
98 // :empty pseudo-selector
99 "doh.is(4, dojo.query('#t > span:empty').length);",
100 "doh.is(6, dojo.query('#t span:empty').length);",
101 "doh.is(0, dojo.query('h3 span:empty').length);",
102 "doh.is(1, dojo.query('h3 :not(:empty)').length);",
103 // escaping of ":" chars inside an ID
104 function silly_IDs1(){
105 doh.t(document.getElementById("silly:id::with:colons"));
106 doh.is(1, dojo.query("#silly\\:id\\:\\:with\\:colons").length);
108 function NodeList_identity(){
109 var foo = new dojo.NodeList([dojo.byId("container")]);
110 doh.is(foo, dojo.query(foo));
114 var doc = dojox.data.dom.createDocument("<ResultSet><Result>One</Result><Result>Two</Result></ResultSet>");
116 console.debug(dojox.data.dom.innerXML(doc.documentElement));
117 console.debug(dojo.query("Result", doc.documentElement).length);
118 }catch(e){ console.debug(e); }
127 <h1>testing dojo.query()</h1>
129 <h3>h3 <span>span</span> endh3 </h3>
130 <!-- comment to throw things off -->
131 <div class="foo bar" id="_foo">
133 <span id="foo"></span>
137 <h3 class="baz" title="thud">h3</h3>
138 <span class="foobar baz foo"></span>
139 <span foo="bar"></span>
140 <span foo="baz bar thud"></span>
141 <!-- FIXME: should foo="bar-baz-thud" match? [foo$=thud] ??? -->
142 <span foo="bar-baz-thudish" id="silly:id::with:colons"></span>
144 <div id="child1" qux="true"></div>
145 <div id="child2"></div>
146 <div id="child3" qux="true"></div>
148 <div qux="true"></div>
149 <input id="notbug" name="bug" type="hidden" value="failed" />
150 <input id="bug" type="hidden" value="passed" />