admin管理员组

文章数量:1335138

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 of Id 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
Add a ment  | 

3 Answers 3

Reset to default 8

getElementById 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.

本文标签: Javascript Console TroubleStack Overflow