Reputation: 19
I'm making a basic card game and I need to return the value of the clicked card but I'm getting an undefined error message.
function flipCard(){
var g = document.getElementById("playingCard").value;
alert(g);
}
<body>
<img src="card.png" id="playingCard" value="20" onclick="flipCard()"/>
</body>
Upvotes: 1
Views: 57
Reputation: 3090
img
tag does not have default property of value
. You can try getAttribute
function.
function flipCard(){
var g = document.getElementById("playingCard").getAttribute('value');
alert(g);
}
Upvotes: 6