removeNamedItem (W3C DOM Core method)

Spec
Version Depr. Static
DOM1 No No
Browser support (more…)
IE5.5+ FF1.5+ SA1.3+ OP9+
Buggy Buggy Buggy Buggy
Returns
Node
Throws
NOT_FOUND_ERR, NO_MODIFICATION_ALLOWED_ERR

Example

var attrs = document.getElementsByTagName('link').item(0).attributes;

var removed = attrs.removeNamedItem('media');

The example above saves the attributes collection of an HTML <link> element, and then attempts to remove an item with the name media from that collection, saving the removed item to the removed variable.

If that item exists in the collection then it will be removed and saved to the removed variable, otherwise this method should throw a DOMException (code 8: NOT_FOUND_ERR).

Arguments

name (DOMString) required

The nodeName of the node to remove.

Description

Remove a node with the specified name from a NamedNodeMap.

If the removed node is an attribute that's attached to an element, and the attribute has a specific default value in this document type, a new attribute with the default value should be automatically created (as well as the corresponding namespaceURI, localName and prefix, if applicable).

Return value

The node that's been removed; or null if no such node exists in the map.

Compatibility

Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.5 2.0 3.0 1.3 2.0 3.0 9.0 9.5
Buggy Buggy Buggy Buggy Buggy Buggy Buggy Buggy Buggy Buggy Buggy

Internet Explorer 5.5 in HTML doesn't implement this method (it returns undefined).

In Internet Explorer 6 and 7 in HTML this method does not actually remove items from an attributes collection, it merely resets their value (the return value may be null, 0, false or an empty string, depending on what type of value IE considers the attribute to have; please see Attr for more information on attribute types in IE).

Opera and Internet Explorer in XML do not throw an exception when attempting to remove an item that doesn't exist; the operation silently fails and the method returns null.

When a removed item corresponds with an attribute that has a default value in this document type, a new attribute is not created to replace it in Internet Explorer, Firefox, Safari and Opera 9.5 (only Opera 9.0 gets this right).

User-contributed notes

There are no comments yet.

Related Products