XPathResult: Eigenschaft singleNodeValue
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.
Die schreibgeschützte Eigenschaft singleNodeValue
des XPathResult
-Interfaces gibt einen Node
-Wert oder null
zurück, falls kein Knoten eines Ergebnisses mit XPathResult.resultType
, das ANY_UNORDERED_NODE_TYPE
oder FIRST_ORDERED_NODE_TYPE
ist, übereinstimmt.
Wert
Der Rückgabewert ist der Node
-Wert des XPathResult
, der durch Document.evaluate()
zurückgegeben wird.
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 Eigenschaft singleNodeValue
.
HTML
<div>XPath example</div>
<div>
Tag name of the element having the text content 'XPath example':
<output></output>
</div>
JavaScript
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 |