English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
getAttributeNode()The method returns the specified attribute of the specified element, and the returned value is of Attr node type
If the given attribute does not exist, the returned value will benullor "" (empty string).
Useattribute.value property to return the value of the attribute node.
If you only want to return the attribute value, please usegetAttribute()methods.
You can find more information in ourIn the HTML DOM attribute objectLearn more about the Attr object.
element.getAttributeNode(attr)
var elem = document.getElementsByTagName("H1")[0]; var attr = elem.getAttributeNode("class").value;Test and See‹/›
getAttributeNode() method is fully supported in all browsers:
Method | |||||
getAttributeNode() | Is | Is | Is | Is | Is |
Parameter | Description |
---|---|
attr | The name of the attribute you want to return |
Return value: | An Attr object representing the specified attribute node |
---|---|
DOM Version: | DOM Level1 |
Get the style attribute value of the element:
var elem = document.getElementsByTagName("H1")[0]; var attr = elem.getAttributeNode("style").value;Test and See‹/›
Get the value of the href attribute node of the anchor element:
var elem = document.getElementsByTagName("a")[0]; var attr = elem.getAttributeNode("href").value;Test and See‹/›
Get the src attribute value of the image element node:
var elem = document.getElementsByTagName("img")[0]; var attr = elem.getAttributeNode("src").value;Test and See‹/›
HTML Tutorial:HTML Attributes
HTML DOM Reference:HTML DOM Attribute Object
HTML DOM Reference:element.getAttribute() method
HTML DOM Reference:element.setAttribute() method
HTML DOM Reference:element.removeAttributeNode() method