my objective is to have an image hidden until a button is pressed to then show the previously hidden image.
Right now I have an image in html with an Id of "yellowrose" that is hidden with this code:
<div id="yellowrose"><img src="https://i.imgur.com/ppfhZa6.jpg" style="visibility:hidden"></div>
In JS I have several things happening with the buttonx.onclick, but I can't seem to make the image visible. Here's my JS code:
var content = document.getElementById("content");
var buttonx = document.getElementById("show-more");
let yellowrose = document.getElementById("yellowrose");
window.onload = function(){
buttonx.onclick = function () {
document.getElementById("yellowrose").style.visibility="visible";
if(content.className == "open") {
//shrink the box
content.className = "";
buttonx.innerHTML = "Continue to the Sunlit Pavillion?";
} else{
//expand the box
content.className = "open";
buttonx.innerHTML = "As you wander through the garden grounds you notice a striking Yellow Rose";
}
}
}
Do you have any suggestions on how I can make the "yellowrose" image visible through the buttonx.onclick function? Thank you.
style="visibility:hidden"
in the img tag to your<div id="yellowrose">
as your JavaScript is targeted toyellowrose
which is div tag not img tag.