close

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

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Uncaught TypeError: Cannot read property ‘appendChild’ of null in javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Uncaught TypeError: Cannot read property ‘appendChild’ of null Error Occurs?

Today I get the following error Uncaught TypeError: Cannot read property ‘appendChild’ of null in javascript.

How To Solve Uncaught TypeError: Cannot read property ‘appendChild’ of null Error ?

  1. How To Solve Uncaught TypeError: Cannot read property 'appendChild' of null Error ?

    To Solve Uncaught TypeError: Cannot read property 'appendChild' of null Error Instead of using your script tag defining the source of your .js file in <head>, place it at the bottom of your HTML code.

  2. Uncaught TypeError: Cannot read property 'appendChild' of null

    To Solve Uncaught TypeError: Cannot read property 'appendChild' of null Error Instead of using your script tag defining the source of your .js file in <head>, place it at the bottom of your HTML code.

Solution 1

There isn’t an element on your page with the id “mainContent” when your callback is being executed.

In the line:

document.getElementById("mainContent").appendChild(p);

the section document.getElementById("mainContent") is returning null

Solution 2

Instead of using your script tag defining the source of your .js file in <head>, place it at the bottom of your HTML code.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment