This article mainly introduces TypeErrordocument. getElementById (...) isnull error cause, this is a very easy to make a low-level error, the need of friends can refer to the next handwritten a simple page for testing, written js part is always reported TypeError document. getElementById (...) is null error. The Code has been read several times and no syntax error is found. No way, I searched the internet to find the document. the syntax of getElementById for finding nodes by id is still a bit exquisite, as follows:
(1) If it is written in front of the node where the id is located, such as the head block, it should be written as follows:
The Code is as follows:
Window. onload = function (){
...... Js Code
}
The above code means to run js after html elements are loaded.
(2) Write it behind the node where the id is located. Otherwise, the error "TypeError: document. getElementById (...) is null" cannot be found.
When jquery code is too much written, it is easy to ignore some js details and record a record for later forgetting.