document.getElementById() not working
Hello, I tried to use event listener on an element but document.getElementById() returns null instead of the element. The problem is that I can't find any problem and I tired the code on multiple online compiler and it worked in all of them but it doesn't work on VScode.
HTML:
JavaScript:
5 Replies
if you load script file in the head add defer attribute on it 😉
Your
<script>
gets run the moment it gets loaded, that is probably before the HTML is fully parsed.
To counter this, you can add defer
to your <script>
, so it gets loaded after the HTML is rendered.The funny part is that I just learned this yesterday
I am so dumb
Naw, some things just take a few times doing them wrong till they stick 😉 just keep at it
Thank you very much!