HTML DOM getAttribute()Method
Examples
Get the value of the link's target attribute:
document.getElementsByTagName("a")[0].getAttribute("target");
Output:
_blank
Try it Yourself »
Definition and Usage
The getAttribute() method gets the value of an attribute by name.
Tip:If you want to return the attribute, use the getAttributeNodemethod.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the getAttribute() method
Syntax
element.getAttribute(attributename)
Parameters
| Parameter | Type | Description |
|---|---|---|
| attributename | String | Required. The value of the attribute you want to get. |
Return Value
| Type | Description |
|---|---|
| String | The specified attribute value |
Technical Details
| DOM Version | Core Level 1 Element Object |
|---|
Other Extensions
Element Object