The read-only resultType
property of the XPathResult
interface represents the type of the result, as defined by the type constants.
Note: This feature is available in Web Workers.
Syntax
var resultType = result.resultType;
Return value
An integer value representing the type of the result, as defined by the type constants.
Constants
Result Type Defined Constant | Value | Description |
ANY_TYPE |
0 |
A result set containing whatever type naturally results from evaluation of the expression. Note that if the result is a node-set then UNORDERED_NODE_ITERATOR_TYPE is always the resulting type. |
NUMBER_TYPE |
1 |
A result containing a single number. This is useful for example, in an XPath expression using the count() function. |
STRING_TYPE |
2 |
A result containing a single string. |
BOOLEAN_TYPE |
3 |
A result containing a single boolean value. This is useful for example, in an XPath expression using the not() function. |
UNORDERED_NODE_ITERATOR_TYPE |
4 |
A result node-set containing all the nodes matching the expression. The nodes may not necessarily be in the same order that they appear in the document. |
ORDERED_NODE_ITERATOR_TYPE |
5 |
A result node-set containing all the nodes matching the expression. The nodes in the result set are in the same order that they appear in the document. |
UNORDERED_NODE_SNAPSHOT_TYPE |
6 |
A result node-set containing snapshots of all the nodes matching the expression. The nodes may not necessarily be in the same order that they appear in the document. |
ORDERED_NODE_SNAPSHOT_TYPE |
7 |
A result node-set containing snapshots of all the nodes matching the expression. The nodes in the result set are in the same order that they appear in the document. |
ANY_UNORDERED_NODE_TYPE |
8 |
A result node-set containing any single node that matches the expression. The node is not necessarily the first node in the document that matches the expression. |
FIRST_ORDERED_NODE_TYPE |
9 |
A result node-set containing the first node in the document that matches the expression. |
Example
The following example shows the use of the resultType
property.
HTML
<div>XPath example</div> <div>Is XPath result a node set: <output></output></div>
JavaScript
var xpath = "//div"; var result = document.evaluate(xpath, document, null, XPathResult.ANY_TYPE, null); document.querySelector("output").textContent = result.resultType >= XPathResult.UNORDERED_NODE_ITERATOR_TYPE &&
result.resultType <= XPathResult.FIRST_ORDERED_NODE_TYPE
;
Result
Specifications
Specification | Status | Comment |
---|---|---|
Document Object Model (DOM) Level 3 XPath Specification The definition of 'XPathResult.resultType' in that specification. |
Recommendation | Initial definition |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
resultType | Chrome Full support Yes | Edge Full support 12 | Firefox Full support Yes | IE ? | Opera Full support Yes | Safari ? | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support Yes | Opera Android Full support Yes | Safari iOS ? | Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support
- Compatibility unknown
- Compatibility unknown