Attr: ownerElement-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 ownerElement
-Eigenschaft des Attr
-Interfaces gibt das Element
zurück, zu dem das Attribut gehört.
Wert
Das Element
, zu dem das Attribut gehört, oder null
, wenn das Attribut mit keinem Element verknüpft ist.
Beispiel
Das folgende Beispiel zeigt den qualifizierten Namen des Elements der ersten beiden Elemente an, wenn wir auf den entsprechenden Button klicken.
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 <svg></button>
<button>Show value for <label></button>
</p>
<p>
Qualified name of the owner element 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.ownerElement.tagName.toLowerCase();
});
i++;
}
Spezifikationen
Specification |
---|
DOM # dom-attr-ownerelement |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
ownerElement |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.