Skip to content
Advertisement

TypeError: Cannot read property ‘appendChild’ of null [closed]

I’m trying to create a blog where i get the information from Firestore database. But I keep getting this error. TypeError: Cannot read property 'appendChild' of null. enter image description here

Here is my HTML code: enter image description here

Here is my JavaScript code: enter image description here

Here is the Firestore Database: enter image description here

Advertisement

Answer

I think the error you are getting isn’t related to Firebase at all but rather to document.querySelector on line 16. The function expects a valid CSS selector to be passed, so if you want to find element by id you should prepend selector with “#”. In your case there is also a typo so at the end it should look like this to work:

let postCollection = document.querySelector('#post-collection');

See https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement