+ 2

how would you write a code that shows or hides an image on a page when the user clicks something?

I want to have images on the page, and let the user click a <button> to show or hide the image. (using HTML, CSS, and javascript). thank you for your help

9th Sep 2018, 2:43 PM
Tyler M
Tyler M - avatar
5 Réponses
+ 7
btn.onclick = function() { if(img.style.display = "none") { img.style.display = "block"; } else { img.style.display = "none"; } } This makes the job, where img is the image element selected with DOM and btn the button selected with DOM...
9th Sep 2018, 2:47 PM
Ledio Deda
Ledio Deda - avatar
+ 7
You can use Javascript for that.. When user clicks button img.style.visibility=“hidden“; Something like that.. 😅
9th Sep 2018, 2:48 PM
$hardul B
$hardul B - avatar
+ 2
if you want that the area the element occupies before not to cgange, you can use opacity: 0%;
9th Sep 2018, 5:25 PM
Bebida Roja
Bebida Roja - avatar
0
hmm am here.......?
9th Sep 2018, 7:28 PM
musa bbj