最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript Console Trouble - Stack Overflow

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论