Document: createExpression() method - Web APIs | MDN

Syntax

js

createExpression(xpathText, namespaceURLMapper)

Parameters

xpathText

A string which is the XPath expression to be compiled.

namespaceURLMapper

A function which maps a namespace prefix to a namespace URL (or null if none needed).

Return value

XPathExpression

Examples

js

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

Specifications

Specification
DOM
# dom-xpathevaluatorbase-createexpression

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.