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).
DomQuery supports most of the CSS3 selectors spec, along with some custom selectors and basic XPath.
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.
The use of @ and quotes are optional. For example, div[@foo='bar'] is also a valid attribute selector.
Collection of matching regular expressions and code snippets. Each capture group within () will be replace the {} in the select statement as specified by their index.
Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=. New operators can be added as long as the match the format c= where c is any character other than space, > <.
Object hash of "pseudo class" filter functions which are used when filtering selections. Each function is passed two parameters:
c : Array An Array of DOM elements to filter.
v : String The argument (if any) supplied in the selector.
A filter function returns an Array of DOM elements which conform to the pseudo class.
In addition to the provided pseudo classes listed above such as first-child
and nth-child
,
developers may add additional, custom psuedo class filters to select elements according to application-specific requirements.
For example, to filter a
elements to only return links to external resources:
Ext.DomQuery.pseudos.external = function(c, v){
var r = [], ri = -1;
for(var i = 0, ci; ci = c[i]; i++){
// Include in result set only if it's a link to an external resource
if(ci.hostname != location.hostname){
r[++ri] = ci;
}
}
return r;
};
Then external links could be gathered with the following statement:
var externalLinks = Ext.select("a:external");
Compiles a selector/xpath query into a reusable function. The returned function takes one parameter "root" (optional), which is the context node from where the query should start.
The selector/xpath query
(optional) Either "select" (the default) or "simple" for a simple selector match
Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)
Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)
An array of elements to filter
The simple selector to test
If true, it returns the elements that DON'T match the selector instead of the ones that match
An Array of DOM elements which match the selector. If there are no matches, and empty Array is returned.
Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)
Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)
An element id, element or array of elements
The simple selector to test
Selects a group of elements.
Selects a group of elements.
The selector/xpath query (can be a comma separated list of selectors)
(optional) The start of the query (defaults to document).
An Array of DOM elements which match the selector. If there are no matches, and empty Array is returned.
Selects a single element.
Selects a single element.
The selector/xpath query
(optional) The start of the query (defaults to document).
The DOM element which matched the selector.
Selects the value of a node, parsing integers and floats. Returns the defaultValue, or 0 if none is specified.
Selects the value of a node, parsing integers and floats. Returns the defaultValue, or 0 if none is specified.
The selector/xpath query
(optional) The start of the query (defaults to document).
Selects the value of a node, optionally replacing null with the defaultValue.
Selects the value of a node, optionally replacing null with the defaultValue.
The selector/xpath query
(optional) The start of the query (defaults to document).