XPathResult: snapshotLength 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 snapshotLength của giao diện
XPathResult đại diện cho số lượng nút trong ảnh chụp kết quả.
Giá trị
Một giá trị số nguyên đại diện cho số lượng nút trong ảnh chụp kết quả.
Ngoại lệ
TYPE_ERR
Trong trường hợp XPathResult.resultType không phải là
UNORDERED_NODE_SNAPSHOT_TYPE hoặc ORDERED_NODE_SNAPSHOT_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 snapshotLength.
HTML
html
<div>XPath example</div>
<div>Number of matched nodes: <output></output></div>
JavaScript
js
const xpath = "//div";
const result = document.evaluate(
xpath,
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null,
);
document.querySelector("output").textContent = result.snapshotLength;
Kết quả
Thông số kỹ thuật
| Specification |
|---|
| DOM> # dom-xpathresult-snapshotlength> |