This question already has an answer here:
So when I write my javascript code in VScode and try to run it in my page an error message appears in my console saying: "Uncaught TypeError: Cannot read property 'addEventListener' of null at app.js:2"
But when I write the same code in the console of the page directly the code is executed without any problems. The code is:
var button = document.querySelector("button");
button.addEventListener("click",function(){
alert("clicked!");});
Aucun commentaire:
Enregistrer un commentaire