Attr: ownerElement プロパティ

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.

ownerElementAttr インターフェイスの読み取り専用プロパティで、この属性が所属する要素 (Element) を返します。

この属性が所属する要素 (Element)、またはこの属性が要素に結びついていない場合は null です。

次の例では、適切なボタンをクリックすると、 2 つの最初の要素の要素の修飾名が表示されます。

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>
  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++;
}

結果

仕様書

Specification
DOM
# dom-attr-ownerelement

ブラウザーの互換性

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
ownerElement

Legend

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

Full support
Full support