1 <div class="body-wrap" xmlns:ext="http://www.extjs.com"><div class="top-tools"><a class="inner-link" href="#Ext.DomQuery-props"><img src="../resources/images/default/s.gif" class="item-icon icon-prop">Properties</a> <a class="inner-link" href="#Ext.DomQuery-methods"><img src="../resources/images/default/s.gif" class="item-icon icon-method">Methods</a> <a class="inner-link" href="#Ext.DomQuery-events"><img src="../resources/images/default/s.gif" class="item-icon icon-event">Events</a> <a class="bookmark" href="../docs/?class=Ext.DomQuery"><img src="../resources/images/default/s.gif" class="item-icon icon-fav">Direct Link</a> </div><h1>Class <a href="source/DomQuery.html#cls-Ext.DomQuery">Ext.DomQuery</a></h1><table cellspacing="0"><tr><td class="label">Package:</td><td class="hd-info">Ext</td></tr><tr><td class="label">Defined In:</td><td class="hd-info"><a href="source/DomQuery.html#cls-Ext.DomQuery">DomQuery.js</a></td></tr><tr><td class="label">Class:</td><td class="hd-info"><a href="source/DomQuery.html#cls-Ext.DomQuery">DomQuery</a></td></tr><tr><td class="label">Extends:</td><td class="hd-info">Object</td></tr></table><div class="description">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).
3 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>
6 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.
8 <h4>Element Selectors:</h4>
10 <li> <b>*</b> any element</li>
11 <li> <b>E</b> an element with the tag E</li>
12 <li> <b>E F</b> All descendent elements of E that have the tag F</li>
13 <li> <b>E > F</b> or <b>E/F</b> all direct children elements of E that have the tag F</li>
14 <li> <b>E + F</b> all elements with the tag F that are immediately preceded by an element with the tag E</li>
15 <li> <b>E ~ F</b> all elements with the tag F that are preceded by a sibling element with the tag E</li>
17 <h4>Attribute Selectors:</h4>
18 <p>The use of @ and quotes are optional. For example, div[@foo='bar'] is also a valid attribute selector.</p>
20 <li> <b>E[foo]</b> has an attribute "foo"</li>
21 <li> <b>E[foo=bar]</b> has an attribute "foo" that equals "bar"</li>
22 <li> <b>E[foo^=bar]</b> has an attribute "foo" that starts with "bar"</li>
23 <li> <b>E[foo$=bar]</b> has an attribute "foo" that ends with "bar"</li>
24 <li> <b>E[foo*=bar]</b> has an attribute "foo" that contains the substring "bar"</li>
25 <li> <b>E[foo%=2]</b> has an attribute "foo" that is evenly divisible by 2</li>
26 <li> <b>E[foo!=bar]</b> has an attribute "foo" that does not equal "bar"</li>
28 <h4>Pseudo Classes:</h4>
30 <li> <b>E:first-child</b> E is the first child of its parent</li>
31 <li> <b>E:last-child</b> E is the last child of its parent</li>
32 <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>
33 <li> <b>E:nth-child(odd)</b> E is an odd child of its parent</li>
34 <li> <b>E:nth-child(even)</b> E is an even child of its parent</li>
35 <li> <b>E:only-child</b> E is the only child of its parent</li>
36 <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>
37 <li> <b>E:first</b> the first E in the resultset</li>
38 <li> <b>E:last</b> the last E in the resultset</li>
39 <li> <b>E:nth(<i>n</i>)</b> the <i>n</i>th E in the resultset (1 based)</li>
40 <li> <b>E:odd</b> shortcut for :nth-child(odd)</li>
41 <li> <b>E:even</b> shortcut for :nth-child(even)</li>
42 <li> <b>E:contains(foo)</b> E's innerHTML contains the substring "foo"</li>
43 <li> <b>E:nodeValue(foo)</b> E contains a textNode with a nodeValue that equals "foo"</li>
44 <li> <b>E:not(S)</b> an E element that does not match simple selector S</li>
45 <li> <b>E:has(S)</b> an E element that has a descendent that matches simple selector S</li>
46 <li> <b>E:next(S)</b> an E element whose next sibling matches simple selector S</li>
47 <li> <b>E:prev(S)</b> an E element whose previous sibling matches simple selector S</li>
48 <li> <b>E:any(S1|S2|S2)</b> an E element which matches any of the simple selectors S1, S2 or S3//\\</li>
50 <h4>CSS Value Selectors:</h4>
52 <li> <b>E{display=none}</b> css value "display" that equals "none"</li>
53 <li> <b>E{display^=none}</b> css value "display" that starts with "none"</li>
54 <li> <b>E{display$=none}</b> css value "display" that ends with "none"</li>
55 <li> <b>E{display*=none}</b> css value "display" that contains the substring "none"</li>
56 <li> <b>E{display%=2}</b> css value "display" that is evenly divisible by 2</li>
57 <li> <b>E{display!=none}</b> css value "display" that does not equal "none"</li>
58 </ul><br><br><i>This class is a singleton and cannot be created directly.</i></div><div class="hr"></div><a id="Ext.DomQuery-props"></a><h2>Public Properties</h2><table cellspacing="0" class="member-table"><tbody><tr><th colspan="2" class="sig-header">Property</th><th class="msource-header">Defined By</th></tr><tr class="property-row expandable "><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.DomQuery-matchers"></a><b><a href="source/DomQuery.html#prop-Ext.DomQuery-matchers">matchers</a></b> : Object<div class="mdesc"><div class="short">Collection of matching regular expressions and code snippets.
59 Each capture group within () will be replace the {} in ...</div><div class="long">Collection of matching regular expressions and code snippets.
60 Each capture group within () will be replace the {} in the select
61 statement as specified by their index.</div></div></td><td class="msource">DomQuery</td></tr><tr class="property-row expandable "><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.DomQuery-pseudos"></a><b><a href="source/DomQuery.html#prop-Ext.DomQuery-pseudos">pseudos</a></b> : Object<div class="mdesc"><div class="short">Object hash of "pseudo class" filter functions which are used when filtering selections. Each function is passed
62 two ...</div><div class="long"><p>Object hash of "pseudo class" filter functions which are used when filtering selections. Each function is passed
63 two parameters:</p><div class="mdetail-params"><ul>
64 <li><b>c</b> : Array<div class="sub-desc">An Array of DOM elements to filter.</div></li>
65 <li><b>v</b> : String<div class="sub-desc">The argument (if any) supplied in the selector.</div></li>
67 <p>A filter function returns an Array of DOM elements which conform to the pseudo class.</p>
68 <p>In addition to the provided pseudo classes listed above such as <code>first-child</code> and <code>nth-child</code>,
69 developers may add additional, custom psuedo class filters to select elements according to application-specific requirements.</p>
70 <p>For example, to filter <code><a></code> elements to only return links to <i>external</i> resources:</p>
72 Ext.DomQuery.pseudos.external = <b>function</b>(c, v){
73 <b>var</b> r = [], ri = -1;
74 <b>for</b>(<b>var</b> i = 0, ci; ci = c[i]; i++){
75 <i>// Include <b>in</b> result set only <b>if</b> it<em>'s a link to an external resource</i>
76 <b>if</b>(ci.hostname != location.hostname){
82 Then external links could be gathered with the following statement:<code><pre>
83 <b>var</b> externalLinks = Ext.select(<em>"a:external"</em>);</code></pre></div></div></td><td class="msource">DomQuery</td></tr></tbody></table><a id="Ext.DomQuery-methods"></a><h2>Public Methods</h2><table cellspacing="0" class="member-table"><tbody><tr><th colspan="2" class="sig-header">Method</th><th class="msource-header">Defined By</th></tr><tr class="method-row expandable "><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.DomQuery-compile"></a><b><a href="source/DomQuery.html#method-Ext.DomQuery-compile">compile</a></b>( <code>String selector</code>, <span title="Optional" class="optional">[<code>String type</code>]</span> )
85 Function<div class="mdesc"><div class="short">Compiles a selector/xpath query into a reusable function. The returned function
86 takes one parameter "root" (optional)...</div><div class="long">Compiles a selector/xpath query into a reusable function. The returned function
87 takes one parameter "root" (optional), which is the context node from where the query should start.<div class="mdetail-params"><strong>Parameters:</strong><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><strong>Returns:</strong><ul><li><code>Function</code><div class="sub-desc"></div></li></ul></div></div></div></td><td class="msource">DomQuery</td></tr><tr class="method-row expandable "><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.DomQuery-filter"></a><b><a href="source/DomQuery.html#method-Ext.DomQuery-filter">filter</a></b>( <code>Array el</code>, <code>String selector</code>, <code>Boolean nonMatches</code> )
89 Array<div class="mdesc"><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><div class="long">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"><strong>Parameters:</strong><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
90 the selector instead of the ones that match</div></li></ul><strong>Returns:</strong><ul><li><code>Array</code><div class="sub-desc">An Array of DOM elements which match the selector. If there are
91 no matches, and empty Array is returned.</div></li></ul></div></div></div></td><td class="msource">DomQuery</td></tr><tr class="method-row expandable "><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.DomQuery-is"></a><b><a href="source/DomQuery.html#method-Ext.DomQuery-is">is</a></b>( <code>String/HTMLElement/Array el</code>, <code>String selector</code> )
93 Boolean<div class="mdesc"><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><div class="long">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"><strong>Parameters:</strong><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><strong>Returns:</strong><ul><li><code>Boolean</code><div class="sub-desc"></div></li></ul></div></div></div></td><td class="msource">DomQuery</td></tr><tr class="method-row expandable "><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.DomQuery-jsSelect"></a><b><a href="source/DomQuery.html#method-Ext.DomQuery-jsSelect">jsSelect</a></b>( <code>String selector</code>, <span title="Optional" class="optional">[<code>Node/String root</code>]</span> )
95 Array<div class="mdesc"><div class="short">Selects a group of elements.</div><div class="long">Selects a group of elements.<div class="mdetail-params"><strong>Parameters:</strong><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/String<div class="sub-desc">(optional) The start of the query (defaults to document).</div></li></ul><strong>Returns:</strong><ul><li><code>Array</code><div class="sub-desc">An Array of DOM elements which match the selector. If there are
96 no matches, and empty Array is returned.</div></li></ul></div></div></div></td><td class="msource">DomQuery</td></tr><tr class="method-row expandable "><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.DomQuery-operators"></a><b><a href="source/DomQuery.html#method-Ext.DomQuery-operators">operators</a></b>()
98 void<div class="mdesc"><div class="short">Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
99 New operator...</div><div class="long">Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
100 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 class="mdetail-params"><strong>Parameters:</strong><ul><li>None.</li></ul><strong>Returns:</strong><ul><li>void</li></ul></div></div></div></td><td class="msource">DomQuery</td></tr><tr class="method-row expandable "><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.DomQuery-selectNode"></a><b><a href="source/DomQuery.html#method-Ext.DomQuery-selectNode">selectNode</a></b>( <code>String selector</code>, <span title="Optional" class="optional">[<code>Node root</code>]</span> )
102 Element<div class="mdesc"><div class="short">Selects a single element.</div><div class="long">Selects a single element.<div class="mdetail-params"><strong>Parameters:</strong><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><strong>Returns:</strong><ul><li><code>Element</code><div class="sub-desc">The DOM element which matched the selector.</div></li></ul></div></div></div></td><td class="msource">DomQuery</td></tr><tr class="method-row expandable "><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.DomQuery-selectNumber"></a><b><a href="source/DomQuery.html#method-Ext.DomQuery-selectNumber">selectNumber</a></b>( <code>String selector</code>, <span title="Optional" class="optional">[<code>Node root</code>]</span>, <code>Number defaultValue</code> )
104 Number<div class="mdesc"><div class="short">Selects the value of a node, parsing integers and floats. Returns the defaultValue, or 0 if none is specified.</div><div class="long">Selects the value of a node, parsing integers and floats. Returns the defaultValue, or 0 if none is specified.<div class="mdetail-params"><strong>Parameters:</strong><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><strong>Returns:</strong><ul><li><code>Number</code><div class="sub-desc"></div></li></ul></div></div></div></td><td class="msource">DomQuery</td></tr><tr class="method-row expandable "><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.DomQuery-selectValue"></a><b><a href="source/DomQuery.html#method-Ext.DomQuery-selectValue">selectValue</a></b>( <code>String selector</code>, <span title="Optional" class="optional">[<code>Node root</code>]</span>, <code>String defaultValue</code> )
106 String<div class="mdesc"><div class="short">Selects the value of a node, optionally replacing null with the defaultValue.</div><div class="long">Selects the value of a node, optionally replacing null with the defaultValue.<div class="mdetail-params"><strong>Parameters:</strong><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><strong>Returns:</strong><ul><li><code>String</code><div class="sub-desc"></div></li></ul></div></div></div></td><td class="msource">DomQuery</td></tr></tbody></table><a id="Ext.DomQuery-events"></a><h2>Public Events</h2><div class="no-members">This class has no public events.</div></div>