removeNamedItem
Summary
Removes an attribute with a given name.
Method of dom/NamedNodeMapdom/NamedNodeMap
Syntax
var attribute = attributes.removeNamedItem(/* see parameter list */);
Parameters
name
- Data-type
- String
The name of an attribute to remove.
Return Value
Returns an object of type DOM NodeDOM Node
The removed attribute.
Examples
The following example shows how to use this method to remove an attribute from an element.
<!doctype html>
<html>
<head>
<title>removeNamedItem example</title>
<script>
function removeAttrib() {
var attributes = document.getElementById("ex").attributes;
attributes.removeNamedItem("title");
}
</script>
</head>
<body>
<!-- Although this is possible, **Please, DON'T!**. Buttons are perfect to be clicked on! -->
<div onclick="removeAttrib();" id="ex" title="This is a tooltip">
Click this DIV and the tooltip will be deactivated.</div>
</body>
</html>
Notes
An attribute that is removed with this method reverts to the default value of the attribute when applicable. This method returns a script error if the user attempts to remove a non-existent attribute node. removeNamedItem was introduced in Microsoft Internet Explorer 6.
Related specifications
- DOM Level 3 Core
- Recommendation
Attributions
Mozilla Developer Network : [NamedNodeMap Article]
Microsoft Developer Network: [Windows Internet Explorer API reference Article]