I am trying to hide/show dynamically an image through JavaScript, but i can't figure out how to do that. I have the following:
let button = document.querySelector('#button');
let msg = document.querySelector('#image');
button.addEventListener('click', ()=>{
msg.classList.toggle('show');
})
#button{
width: 200px;
text-align: center;
padding: 10px;
font-size: 30px;
cursor: pointer;
margin: auto;
}
.hide{
visibility: hidden;
}
.show{
visibility: visible;
}
<div id="image" class="hide">
<img class="screenshot" width="238" height="222" src="https://picsum.photos/200" alt="screenshot" />
</div>
<div id="button">
Click!
</div>
I think that the src="https://picsum.photos/200" must be implemented in the JS page, not in the HTML page.