In general, in the JavaScript console, if it states:
Uncaught TypeError: Object #<HTMLDocument> has no method 'getElementByID'
what is the typical problem in your code? I'm new to JavaScript and in writing a program, this has repeatedly e up and I'm not sure how to fix the problem or what could even possibly be the problem.
In general, in the JavaScript console, if it states:
Uncaught TypeError: Object #<HTMLDocument> has no method 'getElementByID'
what is the typical problem in your code? I'm new to JavaScript and in writing a program, this has repeatedly e up and I'm not sure how to fix the problem or what could even possibly be the problem.
Share Improve this question edited Apr 29, 2012 at 22:37 Ry-♦ 225k56 gold badges492 silver badges498 bronze badges asked Apr 29, 2012 at 22:29 ecode4ecode4 233 bronze badges 1-
user1248795, if indeed the problem was simply that you had
ID
instead ofId
then you should accept either davin's answer or mine. If it was something else, then you should edit the question to make it clearer that there's a further problem. – Gareth McCaughan Commented May 2, 2012 at 9:30
3 Answers
Reset to default 8getElementById
not getElementByID
Lower case d
. JavaScript is case-sensitive.
The typical problem is that you've typed getElementByID
when you meant getElementById
, probably. Alternatively, if that mistyping happened in transcribing the error message rather than in your original code :-), perhaps you did something that you thought would produce a DOM object but that actually produced null
or undefined
or something; there are lots of ways for that to happen.
The right method name is document.getElementById
.