+ 1

Do anyone know how to fix it?

Well image doesn't want to disappear. <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <img src="https://sd.keepcalm-o-matic.co.uk/i-w600/you-re-the-best-congratulations-you-win-d.jpg" id="button" onclick="me()"> <img src="https://sd.keepcalm-o-matic.co.uk/i-w600/you-re-the-best-congratulations-you-win-d.jpg" id="win"> <script> var a = 0; function me(){ a++; } if(a == 1){ win.display.style="none"; } </script> </body> </html>

8th Jun 2018, 12:47 PM
Road_to_ BigStar
Road_to_ BigStar - avatar
3 odpowiedzi
+ 4
var a = 0; var win = document.getElementById("win"); function me(){ a++; if(a == 1){ win.style.display="none"; } }
8th Jun 2018, 12:54 PM
Bebida Roja
Bebida Roja - avatar
+ 2
win is undefined here. Define win first var win = document.querySelector("#id"); //var win = document.getElementById("id"); also works //Set display none to image as win.style.display = "none";
8th Jun 2018, 12:56 PM
Gopal Gautam
Gopal Gautam - avatar
+ 2
Thank you guys :D
8th Jun 2018, 1:01 PM
Road_to_ BigStar
Road_to_ BigStar - avatar