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

15th Dec 2022, 3:24 AM
chase warren
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 }
15th Dec 2022, 4:26 AM
Tibor Santa
Tibor Santa - avatar
+ 1
onload = () = { // You code... 😎 }
15th Dec 2022, 4:25 AM
Solo
Solo - avatar