cannot set property innerhtml of undefined

This question already has an answer here:

I’m so so sorry asking this very repetitive question again, yet as I searched the previous answers I could not find any solutions. In the code below, my browser returns : Uncaught TypeError: Cannot set property ‘innerHTML’ of undefined as I click an the generated links. Would you be kind to help me out? Thank you very much in advance.

Содержание

  1. marked as duplicate by Barmar javascript Users with the javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed. Jul 25 ’14 at 11:20
  2. 4 Answers 4
  3. Not the answer you’re looking for? Browse other questions tagged javascript html or ask your own question.
  4. Related
  5. Hot Network Questions

marked as duplicate by Barmar javascript Users with the javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed. Jul 25 ’14 at 11:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

есть на вашей странице?

Без верстки трудно сказать.
Ошибка скорее всего заключается в том, что не удаётся найти элемент hours

I’m trying to write a pretty simple script to set an element’s innerHTML to the time. However, Javascript keeps throwing a «Cannot set property ‘innerHTML’ of undefined» error. During debugging, I’ve simplified my script to the point that it runs right after element (a ) is coded, so I know it should have loaded already. I’ve also tried running this script as a argument — same error. I can’t tell what I’m doing wrong.

Any help is appreciated!

4 Answers 4

You are not calling getElementById , you are attempting to index it. Since it is not an array and does not expose array-like behavior, the result is undefined . Replace your getElementById[spanId] with getElementById(spanId) .

[] instead of () in document.getElementById(spanid) . getElementById is function, it has to be invoked with () and pass the parameter inside it.

Also missing () after getSeconds()

And now that you have this fixxed add this:

And you have an actual clock 😀

Not the answer you’re looking for? Browse other questions tagged javascript html or ask your own question.

Hot Network Questions

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2019 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0 with attribution required. rev 2019.11.15.35459

Источник: computermaker.info

Понравилась статья? Поделиться с друзьями:
Ок! Компьютер
Добавить комментарий