Friday, 30 January 2015

Onclick get image tag value in html

<html>
<head>
<title>img</title>
 <script>
 function myFunction() {
     var catImage = document.getElementById("catImage"),
    catImageValue = document.getElementById("catImageValue");
//alert("I am an catImageValue box!"+ catImageValue);

catImageValue.innerHTML = "Value = " + catImage.getAttribute("value");
   
}

 </script>
 </head>
  Click on this
 <img id="catImage" src="http://i.imgur.com/Mmfl8.png" width="100px" value="1" />
<div id="catImageValue"></div>
<button onclick="myFunction()">Try it</button>
 </body>
</html>

VIEW DEMO HERE MY Fiddle

http://jsfiddle.net/vipulg/povnd0t2/
DEMO

No comments:

Post a Comment