Attribute value Property - Javascript DOM

Javascript examples for DOM:Attribute

Description

The value property sets or gets the value of the attribute.

Set the attribute value the following Values

Value Description
value Sets the value of the attribute

Return Value

A String, representing the value of the attribute

The following code shows how to Get the value of the <button> element's first attribute:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img src="http://java2s.com/resources/a.png" width="100" height="180">

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {//from ww  w .  j a  v  a2s  . c o m
    var x = document.getElementsByTagName("IMG")[0];
    x.getAttributeNode("src").value = "http://java2s.com/resources/b.png";
    console.log(x.getAttributeNode("src").value);
}
</script>

</body>
</html>

Related Tutorials