JavaScript Element removeAttributeNode() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

Element.removeAttributeNode() removes a specified Attr node from the element and returns that removed node (MDN). Prefer removeAttribute() when you only need to delete by name.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call el.removeAttributeNode. Start with this line.

JavaScript
el.removeAttributeNode(attr)
CallWhat it does
el.removeAttributeNode(attr)Primary signature.
el.removeAttributeNode(...)Call with the arguments your case needs.

Built into the browser. Call removeAttributeNode(...) on an Element — no import required.

Library declarations
JavaScript
el.removeAttributeNode(attr)

Parameters

ParameterDescription
attributeNodeRequired. Attr that belongs to this element

Return Value

Return ValueDescription
*The removed Attr node

JavaScript Examples

Example 1 — Remove lang Attr (MDN)

Get the node, then remove it from the element.

JavaScript
const d = document.getElementById("foo");
const dLang = d.getAttributeNode("lang");
d.removeAttributeNode(dLang);

console.log(d.hasAttribute("lang")); // false
console.log(d.outerHTML);
Try It Yourself

How It Works

  1. Select the element that has lang.
  2. Get the Attr. getAttributeNode("lang") returns the node.
  3. Call removeAttributeNode. That Attr leaves the element (MDN).
  4. Confirm. hasAttribute("lang") is false.

Example 2 — Use the Returned Attr

Capture name and value from the node that was removed.

JavaScript
const el = document.getElementById("foo");
const attr = el.getAttributeNode("lang");
const removed = el.removeAttributeNode(attr);

console.log(removed.name);  // "lang"
console.log(removed.value); // "en-US"
Try It Yourself

How It Works

  1. Get the Attr before removing it.
  2. Remove it. The method returns that same node (MDN).
  3. Read name / value from the return value.
  4. Why use this? When you need the old Attr object, not just a delete-by-name.

Example 3 — Guard Against NotFoundError

Only remove an Attr that still belongs to this element.

JavaScript
const el = document.getElementById("foo");
const attr = el.getAttributeNode("lang");

el.removeAttributeNode(attr); // OK once

try {
  el.removeAttributeNode(attr); // already gone
} catch (err) {
  console.log(err.name); // NotFoundError
}
Try It Yourself

How It Works

  1. First remove succeeds. The Attr leaves the list.
  2. Second remove fails. MDN: NotFoundError.
  3. Wrap in try/catch if you might remove twice.
  4. Safer path: null-check getAttributeNode, or use removeAttribute(name).

Browser Support

Element.removeAttributeNode() is Baseline Widely available on MDN (across browsers since July 2015). Safe for Attr-node workflows.

✓ Baseline Widely available

Element.removeAttributeNode()

Remove an Attr node and get it back — widely supported.

Wide Baseline
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Android WebView Supported · Modern WebView
Full support
removeAttributeNode() Widely available

Bottom line: Use when you already have an Attr. Prefer removeAttribute(name) for everyday deletes by name.

Frequently Asked Questions

It removes the specified Attr node from the element and returns that removed Attr node (MDN).
No. MDN marks Element.removeAttributeNode() as Baseline Widely available (across browsers since July 2015). It is not Deprecated, Experimental, or Non-standard.
An Attr node — typically obtained first with getAttributeNode() or from element.attributes (MDN).
The Attr node that was removed from the element (MDN).
MDN: if you do not need to inspect the Attr node before removing it, removeAttribute(attrName) is simpler.
NotFoundError DOMException when the element's attribute list does not contain the specified Attr node (MDN).

Next: removeAttributeNS()

Learn how to remove a namespaced attribute by URI and name.

removeAttributeNS() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

16 people found this page helpful