Get the value of the class attribute node of an <h1> element:
The result of attr will be:
More "Try it Yourself" examples below.
The getAttributeNode() method returns the attribute node with the specified name of an element, as an Attr object.
Tip: Use the attribute.value property to return the value of the attribute node.
Tip: Use the getAttribute() method if you just want to return the attribute value.
For more information about the Attr object, see The HTML DOM Attribute Object.
Method | |||||
---|---|---|---|---|---|
getAttributeNode() | Yes | Yes | Yes | Yes | Yes |
Parameter | Type | Description |
---|---|---|
attributename | String | Required. The name of the attribute you want to return |
Return Value: | An Attr object, representing the specified attribute node. Note: If the attribute does not exist, the return value is null or an empty string ("") |
---|---|
DOM Version | Core Level 1 Element Object |
Get the value of the target attribute node of an <a> element:
The result of attr will be:
Get the value of the onclick attribute node of a <button> element:
The result of attr will be:
HTML Tutorial: HTML Attributes
HTML DOM Reference: The HTML DOM Attribute Object
HTML DOM Reference: getAttribute() Method
HTML DOM Reference: attribute.value Property
HTML DOM Reference: removeAttributeNode() Method
HTML DOM Reference: setAttributeNode() Method