Skip to content Skip to sidebar Skip to footer

How To Get Value Of Img Tag?

How can i get value of img tag??? in img tag we have one property named 'Value' so i want to know that how can i access this value property in javascript??? I use this code: funct

Solution 1:

Try something like

var product=document.getElementById('prod1').getAttribute('value');

Solution 2:

Um.. I could be way off here, but arn't you looking for the src attribute? I don't think that value is a valid attribute for the <img> tag...

var product=document.getElementById('prod1').src;

As I see it, the "value" of an image would be the path to the image itself.. That is located in the src attribute.

Solution 3:

AFAIK the img-tag normally has no attribute value: http://www.w3schools.com/tags/tag_img.asp

But the solution of Michael should work.

Alternatively you can try it with jQuery:

var product=$('#prod1').attr('value');

Post a Comment for "How To Get Value Of Img Tag?"