HTML DOM getAttribute() Method (original) (raw)
Last Updated : 11 Jul, 2025
The **HTML DOM getAttribute() method is used to retrieve the value of a specified attribute from an HTML element. It returns the attribute's value as a string or null if the attribute doesn't exist.
**Note: It will return a null or an empty string if the specified attribute doesn't exist.
**Syntax
Object.getAttribute(attributename)
**Parameter
| Parameter | Description |
|---|---|
| **name | It is a required parameter with a string type that specifies the name of the attribute that needs to retrieve the value. |
**Example 1: This example illustrates the DOM **getAttribute() method that specifies the value of the attribute for the specified name, of an element.
HTML `
HTML DOM getAttribute() MethodGeeksforGeeks
DOM getAttribute() Method
Submit
`
**Output:

DOM getAttribute() Method
**Example 2: This example illustrates the DOM **getAttribute() method to retrieve the href attribute value of an element.
HTML `
GeeksforGeeks
DOM getAttribute() Method
GeeksforGeeksSubmit
`
**Output:

DOM getAttribute() Method
We have a complete list of HTML DOM methods, to check those please go through this HTML DOM Object Complete reference article.
**Supported Browsers:
- Google Chrome 1.0
- Microsoft Edge 12.0
- Firefox 1.0
- Opera 8.0
- Safari 1.0
We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.