<!DOCTYPE html>
<html>
<head>
<script>
var x=1;
function change()
{
if (x==1)
x=0;
else
x=1;
document.getElementById(test).innerHTML=x;
}
</script>
</head>
<body>
<div id=test></div>
<input type=button value=change onclick=change()>
</body>
</html>
I write the above code to print the value of "x" but this code gives error
Top comments (2)
If this is literal, I would assume its because you have test as a variable instead of as a string "test".
Thanks, Now my code works fine.