Properties Methods Events Direct Link

# Class Ext.DomQuery

Package: | Ext
Defined In: | DomQuery.js
Class: | DomQuery
Extends: | Object

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.

#### Element Selectors:

- * any element
- E an element with the tag E
- E F All descendent elements of E that have the tag F
- E > F or E/F all direct children elements of E that have the tag F
- E + F all elements with the tag F that are immediately preceded by an element with the tag E
- E ~ F all elements with the tag F that are preceded by a sibling element with the tag E

#### Attribute Selectors:

The use of
This class is a singleton and cannot be created directly.

## Public Properties

Property | Defined By
--- | ---
| matchers : Object Collection of matching regular expressions and code snippets. | DomQuery
| pseudos : Object Collection of "pseudo class" processors. Each processor is passed the current nodeset (array) and the argument (if a... Collection of "pseudo class" processors. Each processor is passed the current nodeset (array) and the argument (if any) supplied in the selector. | DomQuery

## Public Methods

Method | Defined By
--- | ---
| compile( `String selector`, [`String type`] ) : Function Compiles a selector/xpath query into a reusable function. The returned function takes one parameter "root" (optional... 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. Parameters: `selector` : String The selector/xpath query `type` : String (optional) Either "select" (the default) or "simple" for a simple selector match Returns: `Function` | DomQuery
| filter( `Array el`, `String selector`, `Boolean nonMatches` ) : Array 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) Parameters: `el` : Array An array of elements to filter `selector` : String The simple selector to test `nonMatches` : Boolean If true, it returns the elements that DON'T match the selector instead of the ones that match Returns: `Array` An Array of DOM elements which match the selector. If there are no matches, and empty Array is returned. | DomQuery
| is( `String/HTMLElement/Array el`, `String selector` ) : Boolean 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) Parameters: `el` : String/HTMLElement/Array An element id, element or array of elements `selector` : String The simple selector to test Returns: `Boolean` | DomQuery
| operators() : void Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=. New operato... 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, > <. Parameters: None. Returns: void | DomQuery
| select( `String selector`, [`Node root`] ) : Array Selects a group of elements. Selects a group of elements. Parameters: `selector` : String The selector/xpath query (can be a comma separated list of selectors) `root` : Node (optional) The start of the query (defaults to document). Returns: `Array` An Array of DOM elements which match the selector. If there are no matches, and empty Array is returned. | DomQuery
| selectNode( `String selector`, [`Node root`] ) : Element Selects a single element. Selects a single element. Parameters: `selector` : String The selector/xpath query `root` : Node (optional) The start of the query (defaults to document). Returns: `Element` The DOM element which matched the selector. | DomQuery
| selectNumber( `String selector`, [`Node root`], `Number defaultValue` ) : Number 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. Parameters: `selector` : String The selector/xpath query `root` : Node (optional) The start of the query (defaults to document). `defaultValue` : Number Returns: `Number` | DomQuery
| selectValue( `String selector`, [`Node root`], `String defaultValue` ) : String Selects the value of a node, optionally replacing null with the defaultValue. Selects the value of a node, optionally replacing null with the defaultValue. Parameters: `selector` : String The selector/xpath query `root` : Node (optional) The start of the query (defaults to document). `defaultValue` : String Returns: `String` | DomQuery

## Public Events

This class has no public events.