I cannot get an image to switch back and forth between 'hidden' and 'show'
I'm using ideas from How to create a hidden <img> in JavaScript?
I have two different buttons, trying one using html and the other to use javascript - If I comment out one line, the light bulb photo is displayed
//document.getElementById("light").style.visibility = "hidden";
That line of code is in my 'init' function
If I do not comment the line, the light stays 'hidden', no matter which of the buttons I click
I don't see any errors in the Web Console Log in Safari
<!DOCTYPE html>
<html>
<body>
<h1>Switch on the Light</h1>
<img id="light" src="WebVuCoolOldBulb-2.jpg" style="width:100px" >
<button type = button
onclick="document.getElementById('light').src.show ='WebVuCoolOldBulb-2.jpg'" >Switch On the Light
</button>
<input type="button" id="onButton" value="ON" />
</body>
<script>
//document.images['light'].style.visibility = hidden;
function init() {
//document.getElementById("light").style.visibility = "hidden";
var onButton = document.getElementById("onButton");
onButton.onclick = function() {
demoVisibility() ;
}
}
function demoVisibility() {
document.getElementById("light").style.visibility = "show";
}
document.addEventListener('readystatechange', function() {
// Seems like a GOOD PRACTICE - keeps me from getting type error I was getting
// https://stackoverflow.com/questions/14207922/javascript-error-null-is-not-an-object
if (document.readyState === "complete") {
init();
}
});
</script>
</html>