is JavaScript code in google
Error: Cannot read properties of null (reading ‘style’)
document.getElementById('splash').style.display = 'none'
Error: Cannot read properties of null (reading ‘style’)
document.getElementById('splash').style.display = 'none'
console.log("Already shown");
}
}
enter image description hereIt shows an error in this code, the code
Uncaught Type Error: Cannot read properties of null (reading ‘style’)
document.getElementById('splash').style.display = 'none'
2
Answers
Try this:
does your element have class name?
If your element does truly exist, then the problem is most likely that you are referencing your js file in a
<script>
tag in the body of your html before the element itself. You need to make sure that the script tag is placed at the complete bottom of the<body>
tag after the element you have defined. Another way is to put the script tag in the html head tag and add a simple property ofdefer="true"
. Lastly, if you do not want to do that, simply in your js just do awindow.onload = () => { //write all your code here }
and with that function when you console.log() the element, it would have loaded.