This article mainly introduces TypeError document.getElementById (...) is null error reason, this is very easy to make a low-level error, the need for friends can refer to the
Today, handwritten a simple page to do the test, write the JS part is always reported TypeError document.getElementById (...) is null this error, the code read several times, the grammar did not find anything wrong, no way, on the internet to search a bit, Just found document.getElementById this according to the ID to find the syntax of the node is a little fastidious, specific as follows:
(1) If it is written in front of the node where the ID is located, such as the head block, write the following:
The code is as follows:
Window.onload=function () {
... js code
}
The above code means to run JS after the HTML element is loaded
(2) write in the ID of the node behind, or will be reported TypeError:document.getElementById (...) is null this can not find the node error.
jquery code more than easy to ignore some of the details of JS, record a pen, in case you forget.