XPathResult: singleNodeValue-Eigenschaft
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since Juli 2015.
Die schreibgeschützte singleNodeValue
-Eigenschaft der
XPathResult
-Schnittstelle gibt einen Node
-Wert zurück oder
null
, falls kein Knoten eines Ergebnisses mit
XPathResult.resultType
ANY_UNORDERED_NODE_TYPE
oder
FIRST_ORDERED_NODE_TYPE
übereinstimmt.
Wert
Der Rückgabewert ist der Node
-Wert des XPathResult
,
zurückgegeben von Document.evaluate()
.
Ausnahmen
TYPE_ERR
Falls XPathResult.resultType
nicht
ANY_UNORDERED_NODE_TYPE
oder FIRST_ORDERED_NODE_TYPE
ist, wird eine
DOMException
vom Typ TYPE_ERR
ausgelöst.
Beispiele
Das folgende Beispiel zeigt die Verwendung der singleNodeValue
-Eigenschaft.
HTML
html
<div>XPath example</div>
<div>
Tag name of the element having the text content 'XPath example':
<output></output>
</div>
JavaScript
js
const xpath = "//*[text()='XPath example']";
const result = document.evaluate(
xpath,
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null,
);
document.querySelector("output").textContent = result.singleNodeValue.localName;
Ergebnis
Spezifikationen
Specification |
---|
DOM> # dom-xpathresult-singlenodevalue> |
Browser-Kompatibilität
Loading…