help me please with Uncaught TypeError: Cannot read property 'style' of null

I am starting to learn to develop in html, css and javascrip and I was applying the example of “requestAnimationFrame” to an exercise I’m doing to understand more. but when I run the code I get an error like this:

“Uncaught TypeError: Can not read property ‘style’ of null”

my code editor is visual studio code and I run everything in the latest version of chrome. and attached the CSS file and javascript fileejercicios.js (384 Bytes)
mover.css (233 Bytes)


<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="mover.css" />
<script src="ejercicios.js"></script>


This line is where the problem is:

var element = document.getElementById("thing");

The element variable is set to null. The reason probably has to do with your code running before the full DOM has loaded. You can fix this by putting your script tag at the bottom of the page just above the closing body tag. You can learn more about other approaches you can take at the following tutorial:

Let me know if that change fixes it for you :slight_smile:


thank you Kirupa for the answer soon, really appreciate that. about your advice its works I did the change and is working finally I will could keep study.

thanks a lot.

1 Like