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:
function addcart()
{
$cartvalue=confirm("Would You like to add This Product to Your Cart?");
if($cartvalue)
{
var product=document.getElementById('prod1').value;
alert(product);
}
}
here prod1 is value of img tag but it display as undefine in alert
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:
function addcart()
{
$cartvalue=confirm("Would You like to add This Product to Your Cart?");
if($cartvalue)
{
var product=document.getElementById('prod1').value;
alert(product);
}
}
here prod1 is value of img tag but it display as undefine in alert
Share Improve this question asked Jan 16, 2013 at 13:48 Adarsh BhattAdarsh Bhatt 11 gold badge1 silver badge1 bronze badge 3- 1 Can you show us the HTML markup? – Anthony Forloney Commented Jan 16, 2013 at 13:49
-
2
prod1
is thevalue
of the img tag or itsid
? Post your HTML please – Michael Berkowski Commented Jan 16, 2013 at 13:49 -
<img>
s don't have values. – Quentin Commented Nov 15, 2022 at 10:11
3 Answers
Reset to default 2Try something like
var product=document.getElementById('prod1').getAttribute('value');
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.
AFAIK the img-tag normally has no attribute value: http://www.w3schools./tags/tag_img.asp
But the solution of Michael should work.
Alternatively you can try it with jQuery:
var product=$('#prod1').attr('value');
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744878512a4598693.html
评论列表(0条)