This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The read-only ownerElement property of the Attr interface returns the Element the attribute belongs to.
The Element the attribute belongs to, or null if the attribute is not linked to an element.
The following example displays the qualified name of the element of the two first elements, when we click on the appropriate button.
<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>
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++;
}
| Specification |
|---|
| DOM> # dom-attr-ownerelement> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
ownerElement |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Attr/ownerElement