+ 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>
3 odpowiedzi
+ 4
var a = 0;
var win = document.getElementById("win");
function me(){
a++;
if(a == 1){
win.style.display="none";
}
}
+ 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";
+ 2
Thank you guys :D