Saturday 23 July 2016

javascript - Why is a DOM element null?

I have this simple HTML file:










I am a paragraph tag


I am an h1 tag


I am a div tag






And this simple script (test.js):



y=document.getElementById("id");
y.style.color="green";


Why on earth is "y" null? The error I'm getting is



TypeError: y is null


I'm sure this is a simple syntax thing that I'm missing, but I can't for the life of me figure it out! Help!



Post Script: Both the html file and the test.js file are in the same folder.

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...