Alon Shmiel
Alon Shmiel

Reputation: 7121

Alert an attribute

I want to print the attribute of isChecked:

<!DOCTYPE html>
<html>
<head>
<script>
function myFunction(){
    alert(document.getElementById('myId').isChecked);
}
</script>
    </head>
<body>

<img id="myId" isChecked="0"/>
<br>
<button  onclick="myFunction();">Click me</button>

</body>
</html>

it prints me undefined

any help appreciated!

Upvotes: 0

Views: 128

Answers (2)

sathish
sathish

Reputation: 800

try,

alert(document.getElementById('myId').getAttribute("isChecked"));

Upvotes: 1

Max Frai
Max Frai

Reputation: 64296

Use getAttribute

alert(document.getElementById('myId').getAttribute("isChecked"));

Upvotes: 9

Related Questions