HTML DOM getAttribute() method
Example
Get the value of the target attribute of the link:
document.getElementsByTagName("a")[0].getAttribute("target");
Output result:
_blank
Try it »
Definition and Usage
The getAttribute() method gets the value of an attribute by its name.
**Tip:** If you want to return the attribute, please use the getAttributeNode method.
Browser support





All major browsers support the getAttribute() method
Syntax
element
.getAttribute(
attributename
)
Parameters
| Parameters | Type | Description |
|---|---|---|
| attributename | String | Required. The attribute value you want to get. |
Return Value
| Type | Description |
|---|---|
| String | The specified attribute value |
Technical Details
| DOM version | Core Level 1 Element Object |
|---|
Element object