The error arises because the elements you are trying to access do not exist in the DOM when the script executes due to the visibility of the map.
Placing your DOM manipulations in the 'initMap' function after confirming the elements are loaded will help ensure they are accessible when you need them.
Ensure that all relevant elements are present in the DOM before trying to manipulate them to avoid issues with 'null' references.
You can also consider using event delegation or verifying visibility of elements before interaction to prevent uncaught TypeErrors.
Collection
[
|
...
]