Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #19465

Re: How do I use getElementById in my situation

From "Jukka K. Korpela" <jkorpela@cs.tut.fi>
Newsgroups comp.lang.javascript
Subject Re: How do I use getElementById in my situation
Date 2013-04-25 12:35 +0300
Organization A noiseless patient Spider
Message-ID <klat6f$mji$1@dont-email.me> (permalink)
References <klar57$cfi$1@dont-email.me> <klas9o$idf$1@dont-email.me> <klassf$l35$1@dont-email.me>

Show all headers | View raw


2013-04-25 12:29, Tony wrote:

> When I do this
> elem = document.getElementById(item);
> elem is null

Please teach your newsreader some habits; it now quoted my message 
comprensively, down to the signature, without marking quotations, and 
placed your text inside my sig!

Anyway, my crystal ball says that your script code is in your <head>, so 
it will be executed before the browser has read the <body>, so it does 
not know any id attribute values.

The simple (though not most elegant) fix is to place the <script> 
element at the very end of the <body>, i.e. right before the end tag 
</body>.

Well, it *could* be something else, too, like using id="Elem0" instead 
of id="elem0".

Please post a self-contained testable example or URL for such a thing, 
if further help is needed.

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

How do I use getElementById in my situation "Tony" <tony.johansson@inport.com> - 2013-04-25 11:00 +0200
  Re: How do I use getElementById in my situation "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-04-25 12:19 +0300
    Re: How do I use getElementById in my situation "Tony" <tony.johansson@inport.com> - 2013-04-25 11:29 +0200
      Re: How do I use getElementById in my situation "Tony" <tony.johansson@inport.com> - 2013-04-25 11:32 +0200
      Re: How do I use getElementById in my situation "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-04-25 12:35 +0300

csiph-web