+ 1
DOM selector help
Am I using the selector wrong? In HTML. <p id = "demo"> test <p> In JavaScript. El = document.getElementById("demo"); But if I do alert (El.innerHTML) I get an error null, while it worked at www3schools https://code.sololearn.com/WNJrsk940ULv/?ref=app
10 ответов
+ 2
Or replace lines 21-22 with:
onload=()=>demo.innerText = textje;
+ 3
put your code inside
window.onload =function(){
//your code
}
+ 2
Because js loads faster than html, and therefore does not see "demo"
+ 1
onclick works, it's just that count reached 15.
+ 1
You need to zero out all variables at the end of the "output" function: count=countFunction=0;
check=[];
And now remove onload.
+ 1
To avoid confusion, initialize these variables on the first line with let and they will still be visible in all functions.
And once again: "onload is not needed since you are accessing the html tag after the html document is fully loaded using a function call on click".
0
Now the onclick doesn't work, prolly need also onload?
0
Dooh , thanks!
0
Where do I put count = 0 when I click button,
0
Yes , thanks but I needed a onload the first time , so if you use global variable in a function they are the same in the 2nd function? If you call the second from the first?