![]() |
VOOZH | about |
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.
Object.getAttribute(attributename)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.
Output:
Example 2: This example illustrates the DOM getAttribute() method to retrieve the href attribute value of an element.
Output:
We have a complete list of HTML DOM methods, to check those please go through this HTML DOM Object Complete reference article.
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.