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 in Web Workers.

Thuộc tính chỉ đọc stringValue của giao diện XPathResult trả về giá trị chuỗi của kết quả khi XPathResult.resultTypeSTRING_TYPE.

Giá trị

Giá trị trả về là giá trị chuỗi của XPathResult được trả về bởi Document.evaluate().

Ngoại lệ

TYPE_ERR

Trong trường hợp XPathResult.resultType không phải là STRING_TYPE, một DOMException kiểu TYPE_ERR sẽ được ném ra.

Ví dụ

Ví dụ sau đây cho thấy cách sử dụng thuộc tính stringValue.

HTML

html
<div>XPath example</div>
<div>Text content of the &lt;div&gt; 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;

Kết quả

Thông số kỹ thuật

Specification
DOM
# dom-xpathresult-stringvalue

Tương thích trình duyệt