You are here: Reference > JavaScript > client-side > HTML DOM > methods > removeAttributeNode

removeAttributeNode method

Browser support:
Removes the specified attribute node from the current element.
This method can be used for attributes with or without namespaces as well.
If a default value is defined for the removed attribute, then it will be set after the removal. In Internet Explorer, the removeAttributeNode method has a bug; in case of HTML attributes, it removes the specified attribute node but it keeps the removed value for the new attribute.

Syntax:

object.removeAttributeNode (attributeNode);
You can find the related objects in the Supported by objects section below.

Parameters:

attributeNode
Required. Reference to the attribute node to remove.

Return value:

Returns the removed attribute node.

Methods for attributes without namespaces:

Name Browser Description
createAttribute
Creates a new attribute node with the specified name.
getAttribute
Returns the value of the attribute with the specified name from the current element.
getAttributeNode
Returns the attribute node with the specified name from the current element.
getNamedItem
Returns the attribute node with the specified name from the current attributes collection.
hasAttribute
8
Returns whether the current element has an attribute with the specified name or not.
removeAttribute
Removes the attribute with the specified name from the current element.
removeAttributeNode
Removes the specified attribute node from the current element.
removeNamedItem
Removes the attribute with the specified name from the current attributes collection and returns the removed attribute node.
setAttribute
Adds an attribute with the specified name and value to the current element.
setAttributeNode
Adds the specified attribute node to the current element.
setNamedItem
Adds the specified attribute node to the current attributes collection.

Example HTML code 1:

This example illustrates the use of the removeAttributeNode method and demonstrates the related bug in Internet Explorer:
<head>
    <script type="text/javascript">
        function MoveValueAttr () {
            var input1 = document.getElementById ("input1");
            var input2 = document.getElementById ("input2");

            var valueAttr = input1.getAttributeNode ("value");
            if (valueAttr) {
                input1.removeAttributeNode (valueAttr); 
                input2.setAttributeNode (valueAttr);
            }
        }
    </script>
</head>
<body>
    <input id="input1" value="First input field." />
    <input id="input2" value="" />
    <br /><br />
    <button onclick="MoveValueAttr ();">Move the value attribute of the first input field to the second one!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content