Problem with Event Listeners
Hey people, As I was practicing my event listeners, I came across the following issue. Check out this code: <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <center> <h1>Code</h1> <button onclick="a()">Click Here!</button> </center> <script> function a(){ document.querySelector("body").style.color = "red"; } document.querySelector("button").addEventListener("click", function (){ document.querySelector("body").style.backgroundColor = "yellow"; }); </script> </body> </html> Now, at first glance, it seems like there is nothing wrong with this code. However, when I place the Javascript part in the coding area that is for Javascript only, it gives me this: Typerror: The document.querySelector(...) is null. I have no idea why it does that. Can someone help me figure out what is the issue with this code? Pretty please?