Uncaught TypeError: Cannot read property ‘appendChild’ of undefined; Why is this a problem? Uncaught TypeError: Uncaught TypeError: Uncaught TypeError: Cannot read property ‘appendChild’ of undefined attribute ‘appendChild’.
The solution is very simple, put the Js external file in , let the whole page after the implementation of Js will not be unreadable problems. Window.onload = function(){} for internal Js, you can also wrap it with window.onload = function(){} It is executed after the document is loaded. — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — this is the line — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — ——-
Here again (review) to supplement Js knowledge:
Js in may block the transfer of the page and the rendering of the page, meaning that Js in usually executes before rendering the body page. So try not to put JS files in head. You can choose to introduce and execute JavaScript when the DOM is complete or after a specific block.
So to avoid the Js introduced in blocking the transfer and rendering of the page, the general rule is that styles come first, DOM documents come last, scripts come last. Follow the sequence of parsing, rendering, and executing Javascript.