Dieser Inhalt wurde automatisch aus dem Englischen übersetzt, und kann Fehler enthalten. Erfahre mehr über dieses Experiment.

View in English Always switch to English

XPathEvaluator: XPathEvaluator() Konstruktor

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⁩.

Der XPathEvaluator() Konstruktor erstellt einen neuen XPathEvaluator.

Syntax

js
new XPathEvaluator()

Parameter

Keine.

Rückgabewert

Ein neues XPathEvaluator-Objekt.

Beispiele

Anzahl der <div> Elemente zählen

Das folgende Beispiel zeigt die Verwendung der XPathEvaluator Schnittstelle.

HTML

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

JavaScript

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

Ergebnis

Spezifikationen

Specification
DOM
# dom-xpathevaluator-xpathevaluator

Browser-Kompatibilität