Hide element on click not working


(toxford) #1

Anyone know why this isn’t working? Clicking on button doesn’t hide green square. It’s probably some tiny thing I’ve overlooked.

var greensquare = hypeDocument.getElementById("green")

if (greensquare.style.display == "none") {

hypeDocument.getElementById("green").style.display = "block";
}

else if (greensquare.style.display == "block") {

hypeDocument.getElementById("green").style.display = "none";
}

green-test.hype.zip (11.1 KB)


(strmiska) #2

your code should be:

var greensquare = hypeDocument.getElementById("green");

if (greensquare.style.display == "none") {

hypeDocument.getElementById("green").style.display = "block";
}

else {

hypeDocument.getElementById("green").style.display = "none";
}

(toxford) #3

Thank you! I feel a little dumb for missing that, but it’s all part of learning.