+ 1
Can someone please check my javascript code? It is not working and I can’t figure out why..
This is my code: https://code.sololearn.com/WLbRocg4KTJp/?ref=app
2 ответов
+ 7
Brian Bawuah,
The reason why your code acts like that is because the DOM is executed before the JavaScript.
You need to make sure the JavaScript executes before the DOM.
Therefore you need to add window.onload event.
Second is you did not wrote the event listener correct.
It is addEventListener instead of eventListener.
Have a look at the changes, hope it helps👍
https://code.sololearn.com/WaeCNY58Y56Z/?ref=app
+ 2
It's easier to define the function by onclick keyword: <button onclick="myfunc()">