HTML DOM Attributes value property
- Previous Page specified
- Next Page getNamedItem()
- Go to the Previous Level HTML DOM Attributes
Definition and usage
value
Set or return the value of the attribute.
See also:
Instance
Example 1
Get the value of the first attribute:
let value = element.attributes[0].value;
Example 2
Get the value of the "id" attribute:
let value = element.getAttributeNode("id").value;
Example 3
Change the value of the src attribute using the getNamedItem() method:
const nodeMap = document.getElementById("light").attributes; let value = nodeMap.getNamedItem("src").value;
Example 4
Use the getAttributeNode() method:
const element = document.getElementById("light"); element.getAttributeNode("src").value = "bulbon.gif";

Syntax
Return the attribute value:
attribute.value
Set the attribute value:
attribute.value = value
Attribute
Attribute | Description |
---|---|
value | The value of the attribute. |
Return value
Type | Description |
---|---|
String | The value of the attribute. |
Browser support
attribute.value
It is a DOM Level 1 (1998) feature.
All browsers support it:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | 9-11 | Support | Support | Support | Support |
- Previous Page specified
- Next Page getNamedItem()
- Go to the Previous Level HTML DOM Attributes