DEV Community

Discussion on: Need Help About JavaScript Error Log

shahkartik03 profile image

This should happen when there is no element with id 'darkBtn' in document. And this may happen because with condition in above code, the display of darkBtn is none.

I hope this helps you resolve this err.

salmandabbakuti profile image
Salman Dabbakuti

Thats what I said earler.. you disagreed there lol funny😁😁😅. Making conclusion here..

blindfish3 profile image
Ben Calder

The fact that an element is not displayed wouldn't stop you from adding an event listener: the element itselt still exists in the DOM. The most likely answer is that for some reason the element doesn't actually exist.