值
該屬性所屬的 Element,如果屬性未連結到任何元素,則返回 null。
示例
以下示例顯示了當點選相應的按鈕時,前兩個元素的限定名稱。
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++;
}
規範
| 規範 |
|---|
| DOM # dom-attr-ownerelement |
瀏覽器相容性
載入中…