NamedNodeMap: removeNamedItem() 方法

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

NamedNodeMap 接口的 removeNamedItem() 方法会从映射中移除与给定名称对应的 Attr

语法

js
removeNamedItem(attrName)

参数

attrName

要从映射中移除的属性的名称。

返回值

被移除的 Attr

异常

NotFoundError DOMException

如果不存在具有给定名称的属性,则会抛出此异常。

示例

html
<pre test="testValue"></pre>
js
const pre = document.querySelector("pre");
const attrMap = pre.attributes;

let result = `The 'test' attribute initially contains '${attrMap["test"].value}'.\n`;

result += "We remove it.\n\n";
attrMap.removeNamedItem("test");

result += attrMap.getNamedItem("test")
  ? "And 'test' still exists."
  : "And 'test' is no more to be found.";

pre.textContent = result;

规范

规范
DOM
# dom-namednodemap-removenameditem

浏览器兼容性