removeAttributeNode (W3C DOM Core method)
| Version | Depr. | Static |
|---|---|---|
| DOM1 | No | No |
| IE5.5+ | FF1.5+ | SA1.3+ | OP9.5+ |
|---|---|---|---|
| Buggy | Buggy | Buggy | Buggy |
- Returns
Attr- Throws
NO_MODIFICATION_ALLOWED_ERR,NOT_FOUND_ERR
Example
var node = element.getAttributeNode('href');
element.removeAttributeNode(node);
The example above gets a
reference to the href Attr
node of an element, then removes it.
So if the element in that example referred to this HTML:
<a href="http://www.brothercake.com/" rel="me">brothercake</a>
Then the operation would result in this:
<a rel="me">brothercake</a>
Arguments
- attr (
Attr) required The attribute node to remove.
Description
Remove a specified attribute
node (a reference to which can be retrieved with getAttributeNode or getAttributeNodeNS). This method is essentially
the same as removeAttribute, except that
its argument is the attribute node itself, rather than the attribute's
name.
If the attribute has a specific default value in this
document type, a new node should be created with the default value (and
the same namespaceURI, localName and prefix if
applicable).
Unlike all the other attribute methods, there is no namespaced
equivalent for this one — no method called
removeAttributeNodeNS is defined by the
DOM1
Return value
The attribute node that was removed
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 | Full | Buggy |
In Internet Explorer 5.5 in HTML this method is not implemented (it returns undefined).
In Internet Explorer, Firefox, Safari and Opera 9.5 when removing an attribute which has a specific default value in this document type, the attribute is not replaced with the default (only Opera 9.0 gets this right).
In
Internet Explorer 6 and 7 in HTML this method
does not remove attribute nodes, it merely resets them, according to what
type of value IE considers the attribute to have. For an attribute node
that IE considers to be boolean true (such as
disabled, when defined) the value is reset to
false; on a value it considers to be a a number (such
as tabindex) the value is reset to zero; on a value
it considers to be a function (event-handling attributes such as
onclick) the value is reset to
null; on a style attribute this
method has no effect; for all other (string-type) attributes the value is
reset to an empty string.
Footnotes
1 The DOM considers that a
removeAttributeNodeNS method is not required; this
is noted in the DOM FAQ.
User-contributed notes
There are no comments yet.
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.