![]() |
VOOZH | about |
The HTML DOM setAttribute() method is used to get the value of the attribute of the element. By specifying the name of the attribute, it can set the value of that element. If the element is already present then its value is updated.
Syntax:
Object.setAttribute(attributename,value)
Parameters: This method accepts two parameters:
Return Values: This parameter does not return any values.
The below examples show the use of the setAttribute() method.
Example 1: In this example, we will add a href attribute to the anchor tag using the setAttribute() method.
Output:
Example 2: In this example, we will change the type of an input tag to a button using the setAttribute() method.
Output:
We have a complete list of HTML DOM methods, to check those please go through this article.
Supported Browsers: The browser supported by DOM setAttribute()method are listed below: