Attr: prefix-Eigenschaft

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 prefix-Eigenschaft von Attr gibt das Namensraum-Präfix des Attributs zurück oder null, wenn kein Präfix angegeben ist.

Das Präfix wird immer in Kleinbuchstaben dargestellt, unabhängig davon, welche Groß-/Kleinschreibung bei der Erstellung des Attributs verwendet wird.

Hinweis: Nur XML unterstützt Namensräume. HTML tut dies nicht. Das bedeutet, dass das Präfix eines Attributs eines HTML-Elements immer null sein wird.

Außerdem werden nur die Namensräume xml (für das xml:lang-Attribut), xlink (für die Attribute xlink:href, xlink:show, xlink:target und xlink:title) und xpath unterstützt, und dies nur bei SVG- und MathML-Elementen.

Wert

Ein String, der das Präfix des Namensraums enthält, zu dem das Attribut gehört. Wenn keiner vorhanden ist, wird null zurückgegeben.

Beispiel

HTML

html
<svg xml:lang="en-US" class="struct" height="1" width="1">Click me</svg>
<label xml:lang="en-US" class="struct"></label>

<p>
  <button>Show value for &lt;svg&gt;</button>
  <button>Show value for &lt;label&gt;</button>
</p>

<p>
  Prefix of the attribute <code>xml:lang</code>:
  <output id="result">None.</output>
</p>

JavaScript

js
const elements = document.querySelectorAll(".struct");
const buttons = document.querySelectorAll("button");
const outputEl = document.querySelector("#result");

let i = 0;
for (const button of buttons) {
  const element = elements[i];
  button.addEventListener("click", () => {
    const attribute = element.attributes[0];
    outputEl.value = attribute.prefix;
  });
  i++;
}

Spezifikationen

Specification
DOM
# dom-attr-prefix

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
prefix

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Siehe auch