1 <div class="body-wrap">
2 <div class="top-tools">
3 <a class="inner-link" href="#Ext.DomQuery-props"><img src="../resources/images/default/s.gif" class="item-icon icon-prop">Properties</a>
4 <a class="inner-link" href="#Ext.DomQuery-methods"><img src="../resources/images/default/s.gif" class="item-icon icon-method">Methods</a>
5 <a class="inner-link" href="#Ext.DomQuery-events"><img src="../resources/images/default/s.gif" class="item-icon icon-event">Events</a>
6 <a class="bookmark" href="../docs/?class=Ext.DomQuery"><img src="../resources/images/default/s.gif" class="item-icon icon-fav">Direct Link</a>
8 <h1>Class Ext.DomQuery</h1>
9 <table cellspacing="0">
10 <tr><td class="label">Package:</td><td class="hd-info">Ext</td></tr>
11 <tr><td class="label">Defined In:</td><td class="hd-info"><a href="../src/DomQuery.js" target="_blank">DomQuery.js</a></td></tr>
12 <tr><td class="label">Class:</td><td class="hd-info">DomQuery</td></tr>
13 <tr><td class="label">Extends:</td><td class="hd-info">Object</td></tr>
15 <div class="description">
17 Provides high performance selector/xpath processing by compiling queries into reusable functions. New pseudo classes and matchers can be plugged. It works on HTML and XML documents (if a content node is passed in).
\r
19 DomQuery supports most of the <a href="http://www.w3.org/TR/2005/WD-css3-selectors-20051215/#selectors">CSS3 selectors spec</a>, along with some custom selectors and basic XPath.</p>
\r
22 All selectors, attribute filters and pseudos below can be combined infinitely in any order. For example "div.foo:nth-child(odd)[@foo=bar].bar:first" would be a perfectly valid selector. Node filters are processed in the order in which they appear, which allows you to optimize your queries for your document structure.
\r
24 <h4>Element Selectors:</h4>
\r
26 <li> <b>*</b> any element</li>
\r
27 <li> <b>E</b> an element with the tag E</li>
\r
28 <li> <b>E F</b> All descendent elements of E that have the tag F</li>
\r
29 <li> <b>E > F</b> or <b>E/F</b> all direct children elements of E that have the tag F</li>
\r
30 <li> <b>E + F</b> all elements with the tag F that are immediately preceded by an element with the tag E</li>
\r
31 <li> <b>E ~ F</b> all elements with the tag F that are preceded by a sibling element with the tag E</li>
\r
33 <h4>Attribute Selectors:</h4>
\r
34 <p>The use of @ and quotes are optional. For example, div[@foo='bar'] is also a valid attribute selector.</p>
\r
36 <li> <b>E[foo]</b> has an attribute "foo"</li>
\r
37 <li> <b>E[foo=bar]</b> has an attribute "foo" that equals "bar"</li>
\r
38 <li> <b>E[foo^=bar]</b> has an attribute "foo" that starts with "bar"</li>
\r
39 <li> <b>E[foo$=bar]</b> has an attribute "foo" that ends with "bar"</li>
\r
40 <li> <b>E[foo*=bar]</b> has an attribute "foo" that contains the substring "bar"</li>
\r
41 <li> <b>E[foo%=2]</b> has an attribute "foo" that is evenly divisible by 2</li>
\r
42 <li> <b>E[foo!=bar]</b> has an attribute "foo" that does not equal "bar"</li>
\r
44 <h4>Pseudo Classes:</h4>
\r
46 <li> <b>E:first-child</b> E is the first child of its parent</li>
\r
47 <li> <b>E:last-child</b> E is the last child of its parent</li>
\r
48 <li> <b>E:nth-child(<i>n</i>)</b> E is the <i>n</i>th child of its parent (1 based as per the spec)</li>
\r
49 <li> <b>E:nth-child(odd)</b> E is an odd child of its parent</li>
\r
50 <li> <b>E:nth-child(even)</b> E is an even child of its parent</li>
\r
51 <li> <b>E:only-child</b> E is the only child of its parent</li>
\r
52 <li> <b>E:checked</b> E is an element that is has a checked attribute that is true (e.g. a radio or checkbox) </li>
\r
53 <li> <b>E:first</b> the first E in the resultset</li>
\r
54 <li> <b>E:last</b> the last E in the resultset</li>
\r
55 <li> <b>E:nth(<i>n</i>)</b> the <i>n</i>th E in the resultset (1 based)</li>
\r
56 <li> <b>E:odd</b> shortcut for :nth-child(odd)</li>
\r
57 <li> <b>E:even</b> shortcut for :nth-child(even)</li>
\r
58 <li> <b>E:contains(foo)</b> E's innerHTML contains the substring "foo"</li>
\r
59 <li> <b>E:nodeValue(foo)</b> E contains a textNode with a nodeValue that equals "foo"</li>
\r
60 <li> <b>E:not(S)</b> an E element that does not match simple selector S</li>
\r
61 <li> <b>E:has(S)</b> an E element that has a descendent that matches simple selector S</li>
\r
62 <li> <b>E:next(S)</b> an E element whose next sibling matches simple selector S</li>
\r
63 <li> <b>E:prev(S)</b> an E element whose previous sibling matches simple selector S</li>
\r
65 <h4>CSS Value Selectors:</h4>
\r
67 <li> <b>E{display=none}</b> css value "display" that equals "none"</li>
\r
68 <li> <b>E{display^=none}</b> css value "display" that starts with "none"</li>
\r
69 <li> <b>E{display$=none}</b> css value "display" that ends with "none"</li>
\r
70 <li> <b>E{display*=none}</b> css value "display" that contains the substring "none"</li>
\r
71 <li> <b>E{display%=2}</b> css value "display" that is evenly divisible by 2</li>
\r
72 <li> <b>E{display!=none}</b> css value "display" that does not equal "none"</li>
\r
73 </ul><br><br><i>This class is a singleton and cannot be created directly.</i> </div>
75 <div class="hr"></div>
76 <a id="Ext.DomQuery-props"></a>
77 <h2>Public Properties</h2>
78 <table cellspacing="0" class="member-table">
80 <th class="sig-header" colspan="2">Property</th>
81 <th class="msource-header">Defined By</th>
83 <tr class="property-row">
\r
84 <td class="micon"><a class="exi" href="#expand"> </a></td>
\r
86 <a id="Ext.DomQuery-matchers"></a>
\r
87 <b>matchers</b> : Object <div class="mdesc">
\r
88 Collection of matching regular expressions and code snippets. </div>
\r
90 <td class="msource">DomQuery</td>
\r
92 <tr class="property-row alt expandable">
\r
93 <td class="micon"><a class="exi" href="#expand"> </a></td>
\r
95 <a id="Ext.DomQuery-operators"></a>
\r
96 <b>operators</b> : Object <div class="mdesc">
\r
97 <div class="short">Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
98 New operator...</div>
\r
100 Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
101 New operators can be added as long as the match the format <i>c</i>= where <i>c</i> is any character other than space, > <. </div>
\r
104 <td class="msource">DomQuery</td>
\r
106 <tr class="property-row expandable">
\r
107 <td class="micon"><a class="exi" href="#expand"> </a></td>
\r
109 <a id="Ext.DomQuery-pseudos"></a>
\r
110 <b>pseudos</b> : Object <div class="mdesc">
\r
111 <div class="short">Collection of "pseudo class" processors. Each processor is passed the current nodeset (array)
112 and the argument (if an...</div>
\r
114 Collection of "pseudo class" processors. Each processor is passed the current nodeset (array)
115 and the argument (if any) supplied in the selector. </div>
\r
118 <td class="msource">DomQuery</td>
\r
121 <a id="Ext.DomQuery-methods"></a>
122 <h2>Public Methods</h2>
123 <table cellspacing="0" class="member-table">
125 <th class="sig-header" colspan="2">Method</th>
126 <th class="msource-header">Defined By</th>
128 <tr class="method-row expandable">
\r
129 <td class="micon"><a class="exi" href="#expand"> </a></td>
\r
131 <a id="Ext.DomQuery-compile"></a>
\r
132 <b>compile</b>( <code>String selector</code>, <span class="optional" title="Optional">[<code>String type</code>]</span> ) : Function <div class="mdesc">
\r
133 <div class="short">Compiles a selector/xpath query into a reusable function. The returned function
134 takes one parameter "root" (optional)...</div>
\r
136 Compiles a selector/xpath query into a reusable function. The returned function
137 takes one parameter "root" (optional), which is the context node from where the query should start. <div class="mdetail-params">
\r
138 <strong>Parameters:</strong>
\r
139 <ul><li><code>selector</code> : String<div class="sub-desc">The selector/xpath query</div></li><li><code>type</code> : String<div class="sub-desc">(optional) Either "select" (the default) or "simple" for a simple selector match</div></li> </ul>
\r
140 <strong>Returns:</strong>
\r
142 <li><code>Function</code></li>
\r
148 <td class="msource">DomQuery</td>
\r
150 <tr class="method-row alt expandable">
\r
151 <td class="micon"><a class="exi" href="#expand"> </a></td>
\r
153 <a id="Ext.DomQuery-filter"></a>
\r
154 <b>filter</b>( <code>Array el</code>, <code>String selector</code>, <code>Boolean nonMatches</code> ) : Array <div class="mdesc">
\r
155 <div class="short">Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)</div>
\r
157 Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child) <div class="mdetail-params">
\r
158 <strong>Parameters:</strong>
\r
159 <ul><li><code>el</code> : Array<div class="sub-desc">An array of elements to filter</div></li><li><code>selector</code> : String<div class="sub-desc">The simple selector to test</div></li><li><code>nonMatches</code> : Boolean<div class="sub-desc">If true, it returns the elements that DON'T match
160 the selector instead of the ones that match</div></li> </ul>
\r
161 <strong>Returns:</strong>
\r
163 <li><code>Array</code><div class="sub-desc">An Array of DOM elements which match the selector. If there are no matches, and empty Array is returned.</div></li>
\r
169 <td class="msource">DomQuery</td>
\r
171 <tr class="method-row expandable">
\r
172 <td class="micon"><a class="exi" href="#expand"> </a></td>
\r
174 <a id="Ext.DomQuery-is"></a>
\r
175 <b>is</b>( <code>String/HTMLElement/Array el</code>, <code>String selector</code> ) : Boolean <div class="mdesc">
\r
176 <div class="short">Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)</div>
\r
178 Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child) <div class="mdetail-params">
\r
179 <strong>Parameters:</strong>
\r
180 <ul><li><code>el</code> : String/HTMLElement/Array<div class="sub-desc">An element id, element or array of elements</div></li><li><code>selector</code> : String<div class="sub-desc">The simple selector to test</div></li> </ul>
\r
181 <strong>Returns:</strong>
\r
183 <li><code>Boolean</code></li>
\r
189 <td class="msource">DomQuery</td>
\r
191 <tr class="method-row alt expandable">
\r
192 <td class="micon"><a class="exi" href="#expand"> </a></td>
\r
194 <a id="Ext.DomQuery-select"></a>
\r
195 <b>select</b>( <code>String selector</code>, <span class="optional" title="Optional">[<code>Node root</code>]</span> ) : Array <div class="mdesc">
\r
196 <div class="short">Selects a group of elements.</div>
\r
198 Selects a group of elements. <div class="mdetail-params">
\r
199 <strong>Parameters:</strong>
\r
200 <ul><li><code>selector</code> : String<div class="sub-desc">The selector/xpath query (can be a comma separated list of selectors)</div></li><li><code>root</code> : Node<div class="sub-desc">(optional) The start of the query (defaults to document).</div></li> </ul>
\r
201 <strong>Returns:</strong>
\r
203 <li><code>Array</code><div class="sub-desc">An Array of DOM elements which match the selector. If there are no matches, and empty Array is returned.</div></li>
\r
209 <td class="msource">DomQuery</td>
\r
211 <tr class="method-row expandable">
\r
212 <td class="micon"><a class="exi" href="#expand"> </a></td>
\r
214 <a id="Ext.DomQuery-selectNode"></a>
\r
215 <b>selectNode</b>( <code>String selector</code>, <span class="optional" title="Optional">[<code>Node root</code>]</span> ) : Element <div class="mdesc">
\r
216 <div class="short">Selects a single element.</div>
\r
218 Selects a single element. <div class="mdetail-params">
\r
219 <strong>Parameters:</strong>
\r
220 <ul><li><code>selector</code> : String<div class="sub-desc">The selector/xpath query</div></li><li><code>root</code> : Node<div class="sub-desc">(optional) The start of the query (defaults to document).</div></li> </ul>
\r
221 <strong>Returns:</strong>
\r
223 <li><code>Element</code><div class="sub-desc">The DOM element which matched the selector.</div></li>
\r
229 <td class="msource">DomQuery</td>
\r
231 <tr class="method-row alt expandable">
\r
232 <td class="micon"><a class="exi" href="#expand"> </a></td>
\r
234 <a id="Ext.DomQuery-selectNumber"></a>
\r
235 <b>selectNumber</b>( <code>String selector</code>, <span class="optional" title="Optional">[<code>Node root</code>]</span>, <code>Number defaultValue</code> ) : Number <div class="mdesc">
\r
236 <div class="short">Selects the value of a node, parsing integers and floats. Returns the defaultValue, or 0 if none is specified.</div>
\r
238 Selects the value of a node, parsing integers and floats. Returns the defaultValue, or 0 if none is specified. <div class="mdetail-params">
\r
239 <strong>Parameters:</strong>
\r
240 <ul><li><code>selector</code> : String<div class="sub-desc">The selector/xpath query</div></li><li><code>root</code> : Node<div class="sub-desc">(optional) The start of the query (defaults to document).</div></li><li><code>defaultValue</code> : Number<div class="sub-desc"></div></li> </ul>
\r
241 <strong>Returns:</strong>
\r
243 <li><code>Number</code></li>
\r
249 <td class="msource">DomQuery</td>
\r
251 <tr class="method-row expandable">
\r
252 <td class="micon"><a class="exi" href="#expand"> </a></td>
\r
254 <a id="Ext.DomQuery-selectValue"></a>
\r
255 <b>selectValue</b>( <code>String selector</code>, <span class="optional" title="Optional">[<code>Node root</code>]</span>, <code>String defaultValue</code> ) : String <div class="mdesc">
\r
256 <div class="short">Selects the value of a node, optionally replacing null with the defaultValue.</div>
\r
258 Selects the value of a node, optionally replacing null with the defaultValue. <div class="mdetail-params">
\r
259 <strong>Parameters:</strong>
\r
260 <ul><li><code>selector</code> : String<div class="sub-desc">The selector/xpath query</div></li><li><code>root</code> : Node<div class="sub-desc">(optional) The start of the query (defaults to document).</div></li><li><code>defaultValue</code> : String<div class="sub-desc"></div></li> </ul>
\r
261 <strong>Returns:</strong>
\r
263 <li><code>String</code></li>
\r
269 <td class="msource">DomQuery</td>
\r
272 <a id="Ext.DomQuery-events"></a>
273 <h2>Public Events</h2>
274 <div class="no-members">This class has no public events.</div>