I have an image within a popup that I would like to be swapped out with another image when clicked. I check localStorage to know whether the “on” or “off” button should be displayed.
popup.html:
<body>
<div>
<img id="onOffButton" src="img/on_button.png" onclick="onOff()" />
</div>
</body>
popup.js:
function onOff() {
var onOffButton = document.getElementById("onOffButton");
if (localStorage.ToneSet === "off") {
onOffButton.src="img/on_button.png";
} else {
onOffButton.src="img/off_button.png";
}
}
Currently my localStorage.ToneSet is set to “on” so my image should flip from “on_button.png” to “off_button.png”, but it continues to display on_button.png. Any idea what I’m doing wrong? Thanks.
Maybe something like this http://jsfiddle.net/EX2hj/1/