removeNamedItem method
Removes an attribute specified with the name property from an element by using the attributes collection.
![]() |
Syntax
var retval = attributes.removeNamedItem(bstrName);Parameters
Return value
Type: IHTMLDOMAttribute
Returns an attribute removed from the document if successful, otherwise null.Standards information
Remarks
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.
Examples
The following example shows how to use this method to remove an attribute from an element.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/removeNamedItemEx1.htm
<!DOCTYPE html>
<html>
<head>
<title>removeNamedItem Method Sample</title>
</head>
<body>
<h1>removeNamedItem Method Sample</h1>
<p>Hover over the below <strong>div</strong> to see the tooltip. Then, click
the <strong>div</strong> and hover over it again and note that the tooltip has been remove.</p>
<div id="myDIV"
style="background-color: #96F; color: #FFF; border-style: outset; border-width: 4px; border-color: #FF6; width: 350px; text-align: center; cursor: pointer;"
title="THIS IS A TOOLTIP">
Click this <strong>div</strong> to remove its tooltip attribute.
</div>
<script>
document.getElementById('myDIV').addEventListener('click', removeAttrib, false);
function removeAttrib(evt) {
var myDIV = evt.target;
console.log(myDIV);
var oAttrColl = myDIV.attributes;
console.log(oAttrColl.getNamedItem('title').textContent);
oAttrColl.removeNamedItem('title');
console.log(oAttrColl.getNamedItem('title'));
}
</script>
</body>
</html>
See also
Show:
