addEventListener issue

Greetings

i have an error message popping up in my console saying “Uncaught” typeError: can not read properties of null (reading ‘addEventListener’) at js file.

i had this issue before and fixed it i wrote my first eventListener. it came up again at line 10, i wrote it exactly the same way but it would not work.

i am trying to add a popup overlay to an html page. the first event is to trigger it. the 2nd one with the error now is for closing the popup.

check out.console
checkout

Try moving the script element down so it is the last line in the body element

1 Like

You can also add the defer attribute to the script element. But I would strongly suggest keeping the element position consistent. It is just confusing if it ends up in between page content.


Your code cannot interact with content that is loaded after the code is loaded. The loading of the code must either wait for all the content to load or you must place the code so that the loading logically happens after the content.

1 Like