值
该属性所属的 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 |
浏览器兼容性
加载中…