The button in this script is supposed to be able to make an image appear and disappear.
The code works fine, after the first time the image appears. I want the image to be hidden at first, and when the button is clicked, I want it to make it visible, but the button needs to be double-clicked at first, and then it properly works. It is annoying, how can I fix it?
Code:
(It's simple I know, I started out yesterday)
<!DOCTYPE html>
<html>
<meta charset= "utf-8">
<head>
<title>cat</title>
<style>
#flyingcat {
visibility: hidden;
}
</style>
</head>
<body>
<button onclick="show()">KΛΙΚ ΓΙΑ ΝΟΥΝΤΖ</button>
<div id="flyingcat">
<img src="http://i0.kym-cdn.com/entries/icons/original/000/002/232/bullet_cat.jpg"> <br>
<p>hey</p>
</div>
</body>
<script>
function show() {
var x = document.getElementById("flyingcat");
if (x.style.visibility === "hidden") {
x.style.visibility = "visible";
} else {
x.style.visibility = "hidden";
}
}
</script>
</html>