HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Get the value of the first attribute
The value
property sets or returns the value of an attribute.
Return the attribute value:
Set the attribute value:
Property | Description |
value | The value of the attribute. |
Type | Description |
A string | The value of the attribute. |
function lightOn() { const element = document.getElementsByTagName("IMG")[0]; const attr = element.getAttributeNode("src"); attr.value = "pic_bulbon.gif"; }
Change the value of the src attribute of an image:
Use the getNamedItem() method:
const nodeMap = document.getElementById("light").attributes;
let value = nodeMap.getNamedItem("src").value;
Try it Yourself »
Use the getAttributeNode() method:
const element = document.getElementById("light");
element.getAttributeNode("src").value = "pic_bulbon.gif";
Try it Yourself »
attribute.value
is a DOM Level 1 (1998) feature.
It is fully supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |