HTML DOM Attributes value property

Definition and usage

value Set or return the value of the attribute.

See also:

attribute.name attribute

attributes.getNamedItem() method

Instance

Example 1

Get the value of the first attribute:

let value = element.attributes[0].value;

Try it yourself

Example 2

Get the value of the "id" attribute:

let value = element.getAttributeNode("id").value;

Try it yourself

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;

Try it yourself

Example 4

Use the getAttributeNode() method:

const element = document.getElementById("light");
element.getAttributeNode("src").value = "bulbon.gif";

Try it yourself

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