0
Why is my button not working
My button âbtn_11 is not workingâ and I donât know why https://code.sololearn.com/W7yz4r496F6p/?ref=app
2 Answers
+ 3
The problem is that your JavaScript is executed even before the main body of the html is rendered. So you can see in console error that the element you were trying to capture with queryselector was null.
Solution is wrap your code inside a function and execute it when the html is loaded. You can do it with anonymous function like this. Insert first line in JS code:
window.onload = () => {
And at the very end close the bracket
}
+ 1
onload = () = {
// You code... đ
}