Document: Methode createExpression()
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.
Diese Methode kompiliert ein XPathExpression
, das dann für (wiederholte) Auswertungen verwendet werden kann.
Sie müssen diese Methode auf demselben Dokument aufrufen, auf dem Sie den Ausdruck ausführen.
Syntax
createExpression(xpathText, namespaceURLMapper)
Parameter
xpathText
-
Ein String, der den zu kompilierenden XPath-Ausdruck darstellt.
namespaceURLMapper
-
Eine Funktion, die ein Namespace-Präfix einer Namespace-URL zuordnet (oder null, wenn keine benötigt wird).
Rückgabewert
Beispiele
const xpathExpr = document.createExpression("//div");
const xpathResult = xpathExpr.evaluate(document); // returns an XPathResult object
const nodeContext = document.querySelector("nav");
// Re-using the XPathExpression "xpathExpr"
const otherResult = xpathExpr.evaluate(nodeContext); // returns an XPathResult object
Spezifikationen
Specification |
---|
DOM # dom-xpathevaluatorbase-createexpression |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
createExpression |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support