You are on the editable version of MDN Web Docs

MDN 웹 문서 사용자로 보기:

이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 참여해서 번역을 마치도록 도와 주세요!
English (US)의 문서도 읽어보세요.

The XPathEvaluator interface allows to compile and evaluate XPath expressions.

It is implemented by the Document interface.


Creates a parsed XPath expression with resolved namespaces.
Adapts any DOM node to resolve namespaces allowing the XPath expression to be evaluated relative to the context of the node where it appeared within the document.
Evaluates an XPath expression string and returns a result of the specified type if possible.


The following example shows the use of the XPathEvaluator interface.


<div>XPath example</div>
<div>Number of &lt;div&gt;s: <output></output></div>


var xpath = "//div";
var evaluator = new XPathEvaluator();
var expression = evaluator.createExpression("//div");
var result = expression.evaluate(document, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE);
document.querySelector("output").textContent = result.snapshotLength;



Specification Status Comment
Document Object Model (DOM) Level 3 XPath Specification
The definition of 'XPathEvaluator' in that specification.
Recommendation Initial definition

Browser compatibility

No compatibility data found. Please contribute data for "api.XPathEvaluator" (depth: 1) to the MDN compatibility data repository.

See also

문서 태그 및 공헌자

이 페이지의 공헌자: mdnwebdocs-bot, Sebastianz
최종 변경자: mdnwebdocs-bot,