XPathResult: stringValue property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Note: This feature is available inWeb Workers.
The read-onlystringValue property of theXPathResult interface returns the string value of a result withXPathResult.resultType beingSTRING_TYPE.
In this article
Value
The return value is the string value of theXPathResult returned byDocument.evaluate().
Exceptions
TYPE_ERR
In caseXPathResult.resultType is notSTRING_TYPE, aDOMException of typeTYPE_ERR is thrown.
Examples
The following example shows the use of thestringValue property.
HTML
html
<div>XPath example</div><div>Text content of the <div> above: <output></output></div>JavaScript
js
const xpath = "//div/text()";const result = document.evaluate( xpath, document, null, XPathResult.STRING_TYPE, null,);document.querySelector("output").textContent = result.stringValue;Result
Specifications
| Specification |
|---|
| DOM> # dom-xpathresult-stringvalue> |