Drumbo1969
Drumbo1969

Reputation: 19

No value returned on img tag

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

Answers (1)

Thum Choon Tat
Thum Choon Tat

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

Related Questions