DEV Community

loading...

Discussion on: Need Help About JavaScript Error Log

Collapse
shahkartik03 profile image
shahkartik03

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.

Collapse
salmandabbakuti profile image
Salman Dabbakuti

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

Collapse
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.