大网数据广告活动
Web 标准与前端开发

Element:removeAttributeNode() 方法

· 52CE 我爱测

Element 接口的 **`removeAttributeNode()`** 方法从元素中移除指定的属性(Attr)节点。

DOM

Element 接口的 removeAttributeNode() 方法从元素中移除指定的属性(Attr)节点。

如果你不想在移除属性节点之前检查它是否存在,那么可以改用 Element.removeAttribute() 方法。

语法

removeAttributeNode(attributeNode)

参数

  • attributeNode
    • : 要从元素中删除的属性节点。

返回值

移除的属性节点。

异常

  • NotFoundError DOMException
    • : 若元素的属性列表中不包含指定属性节点,则抛出该异常。

示例

// 给定:<div id="top" align="center" />
const d = document.getElementById("top");
const d_align = d.getAttributeNode("align");
d.removeAttributeNode(d_align);
// 现在 align 已被删除:<div id="top" />

备注

如果删除有默认值的属性,则会立刻用具有默认值的属性替换。在适用时,替换的属性具有相同的命名空间 URI、本地名称以及原始前缀。

并没有 removeAttributeNodeNS 方法;removeAttributeNode 方法可以删除命名空间限定属性和非命名空间限定属性。

规范

浏览器兼容性

参见

  • Document.createAttribute()
  • Element.getAttributeNode()
  • Element.setAttributeNode()

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。