JavaScript Element removeAttributeNS() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

Element.removeAttributeNS() removes an attribute in a given namespace from the element (MDN). For ordinary HTML without a namespace, prefer removeAttribute(). Returns undefined.

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

Syntax

Call el.removeAttributeNS. Start with this line.

JavaScript
el.removeAttributeNS(namespace, attrName)
CallWhat it does
el.removeAttributeNS(namespace, attrName)Primary signature.
el.removeAttributeNS(...)Call with the arguments your case needs.

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

Library declarations
JavaScript
el.removeAttributeNS(namespace, attrName)

Parameters

ParameterDescription
namespaceRequired. Namespace URI string
attrNameRequired. Local attribute name to remove

Return Value

Return ValueDescription
*Always undefined

JavaScript Examples

Example 1 — Remove Namespaced Attr (MDN)

Delete specialAlign in a custom namespace.

JavaScript
const NS = "http://www.mozilla.org/ns/specialspace";
const d = document.getElementById("div1");

d.setAttributeNS(NS, "special:specialAlign", "utterleft");
d.removeAttributeNS(NS, "specialAlign");

console.log(d.hasAttributeNS(NS, "specialAlign")); // false
Try It Yourself

How It Works

  1. Set with a qualified name. setAttributeNS uses special:specialAlign.
  2. Remove with the local name. Pass "specialAlign" (MDN).
  3. Same namespace URI on set and remove.
  4. Result: the namespaced attribute is gone.

Example 2 — Verify with hasAttributeNS

Confirm the attribute is present, then gone.

JavaScript
const NS = "http://example.com/ns";
const el = document.getElementById("box");

el.setAttributeNS(NS, "ex:flag", "1");
console.log(el.hasAttributeNS(NS, "flag")); // true

el.removeAttributeNS(NS, "flag");
console.log(el.hasAttributeNS(NS, "flag")); // false
Try It Yourself

How It Works

  1. Create the attr under a namespace.
  2. Check before. hasAttributeNS is true.
  3. Remove it with the same URI + local name.
  4. Check after. hasAttributeNS is false.

Example 3 — Prefer removeAttribute for HTML

No namespace? Use the simpler API (MDN advice).

JavaScript
const el = document.getElementById("box");

// Everyday HTML — no namespace
el.removeAttribute("title");

// Only when you truly need a namespace
// el.removeAttributeNS(NS, "localName");
Try It Yourself

How It Works

  1. Plain HTML attrs do not need a namespace URI.
  2. Call removeAttribute. One argument — the name (MDN).
  3. Reserve NS APIs for SVG / XML / custom namespaces.
  4. Same idea as set: setAttribute vs setAttributeNS.

Browser Support

Element.removeAttributeNS() is Baseline Widely available on MDN (across browsers since July 2015). Safe for SVG/XML namespace work.

✓ Baseline Widely available

Element.removeAttributeNS()

Remove a namespaced attribute by URI and local name — 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
removeAttributeNS() Widely available

Bottom line: Use for real namespaces (SVG/XML). Prefer removeAttribute() for ordinary HTML attributes.

Frequently Asked Questions

It removes the specified attribute with the specified namespace from an element (MDN).
No. MDN marks Element.removeAttributeNS() as Baseline Widely available (across browsers since July 2015). It is not Deprecated, Experimental, or Non-standard.
namespace — a string with the attribute namespace URI. attrName — the attribute’s local name to remove (MDN example uses specialAlign, not the prefix).
MDN: if you work with HTML and do not need to specify the attribute as part of a namespace, use removeAttribute(attrName) instead.
undefined. There is no return value (MDN).
Call hasAttributeNS(namespace, localName) afterward. It should return false when the namespaced attribute is gone.

Next: replaceChildren()

Learn how to replace all of an element’s children in one call.

replaceChildren() 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.

14 people found this page helpful