Uncaught TypeError: Cannot read property 'children' of null

Created At: 2023-01-03 01:23:53 Updated At: 2023-08-19 18:08:59

The above error for javascript happens due to many reasons we get Uncaught TypeError: Cannot read property 'children' of null

  • 1. maybe your document id is wrong
  • 2. maybe querySelector is wrong
  • 3. maybe DOM object is not ready

Now first you need to check if your document Id which you get through document.getElementById() is correct. This string must be correct one.

It's same for the querySelector. 

One big reason it happens due to DOM object is not ready, which means your document ID doesn't exist in the DOM at the moment of execution of this code.

Move your javascript files or scripts out of the head tag and you should be good. It's better you put the js content before </body> tag. 

So move it to the right place and don't put in the <head></head> tag section.

Try copying your <script>code</script> right before the </body> tag.

If the above solution did not work, then put your javascript code after </body> tag.

React Native tutorial with Nodejs restful api

Comment

Add Reviews