HTML DOM Attributes value attribute
- Föregående sida specified
- Nästa sida getNamedItem()
- Åter till föregående nivå 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 of the image, 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 attribute value:
attribute.value
Set 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 web browsers support it:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Stöd | 9-11 | Stöd | Stöd | Stöd | Stöd |
- Föregående sida specified
- Nästa sida getNamedItem()
- Åter till föregående nivå HTML DOM Attributes