-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
62 lines (43 loc) · 1.23 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
title: "XPathResult: stringValue property"
short-title: stringValue
slug: Web/API/XPathResult/stringValue
page-type: web-api-instance-property
browser-compat: api.XPathResult.stringValue
---
{{APIRef("DOM XPath")}} {{AvailableInWorkers}}
The read-only **`stringValue`** property of the
{{domxref("XPathResult")}} interface returns the string value of a result with
{{domxref("XPathResult.resultType")}} being `STRING_TYPE`.
## Value
The return value is the string value of the `XPathResult` returned by
{{domxref("Document.evaluate()")}}.
### Exceptions
#### TYPE_ERR
In case {{domxref("XPathResult.resultType")}} is not `STRING_TYPE`, an
{{domxref("XPathException")}} of type `TYPE_ERR` is thrown.
## Examples
The following example shows the use of the `stringValue` 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
{{EmbedLiveSample('Examples', 400, 70)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}