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


Groups > comp.lang.javascript > #21609 > unrolled thread

FAQ Topic - Why does my code fail to access an element? (2013-10-15)

Started by"FAQ server" <javascript@dotinternet.be>
First post2013-10-14 23:00 +0000
Last post2013-10-25 22:36 +0200
Articles 6 — 5 participants

Back to article view | Back to comp.lang.javascript


Contents

  FAQ Topic - Why does my code fail to access an element? (2013-10-15) "FAQ server" <javascript@dotinternet.be> - 2013-10-14 23:00 +0000
    Re: FAQ Topic - Why does my code fail to access an element? (2013-10-15) Osmo Saarikumpu <osmo@weppipakki.com> - 2013-10-15 08:26 +0300
      Re: FAQ Topic - Why does my code fail to access an element? (2013-10-15) "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-10-15 10:01 +0300
      Re: FAQ Topic - Why does my code fail to access an element? (2013-10-15) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-10-25 21:51 +0200
    Re: FAQ Topic - Why does my code fail to access an element? (2013-10-15) Kale <kalezwe@gmail.com> - 2013-10-24 20:10 -0700
      Re: FAQ Topic - Why does my code fail to access an element? (2013-10-15) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-10-25 22:36 +0200

#21609 — FAQ Topic - Why does my code fail to access an element? (2013-10-15)

From"FAQ server" <javascript@dotinternet.be>
Date2013-10-14 23:00 +0000
SubjectFAQ Topic - Why does my code fail to access an element? (2013-10-15)
Message-ID<525c7776$0$298$14726298@news.sunsite.dk>
-----------------------------------------------------------------------
FAQ Topic - Why does my code fail to access an element?
-----------------------------------------------------------------------

An element can only be accessed after it exists in the document.

Either:
A) include your script after the HTML element it refers to, or
B) use the `"load"` event to trigger your script.

Example A:

<div id="snurgle">here</div>
<script type="text/javascript">
// Don't forget var.
var snurgleEl = document.getElementById("snurgle");
window.alert(snurgleEl.parentNode);
</script>

Example B:

// In the HEAD.
<script type="text/javascript">
window.onload = function(){
var snurgleEl = document.getElementById("snurgle");
};
</script>

Other problems can include::
----------------------------

* invalid HTML

* two elements with the same `name` or `id`

* use of an unsafe name: http://jibbering.com/names/


The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/

-- 

The sendings of these daily posts are proficiently hosted
by http://www.pair.com.

[toc] | [next] | [standalone]


#21610

FromOsmo Saarikumpu <osmo@weppipakki.com>
Date2013-10-15 08:26 +0300
Message-ID<l3ijlu$7v4$1@dont-email.me>
In reply to#21609
15.10.2013 2:00, FAQ server kirjoitti:
> * use of an unsafe name: http://jibbering.com/names/

404.

-- 
Best wishes,
Osmo

[toc] | [prev] | [next] | [standalone]


#21611

From"Jukka K. Korpela" <jkorpela@cs.tut.fi>
Date2013-10-15 10:01 +0300
Message-ID<l3ip84$sl1$1@dont-email.me>
In reply to#21610
2013-10-15 8:26, Osmo Saarikumpu wrote:

 > 15.10.2013 2:00, FAQ server kirjoitti:
>> * use of an unsafe name: http://jibbering.com/names/
>
> 404.

The correct URL is
http://jibbering.com/faq/names/

But I’m afraid the FAQ is frozen (and soon frozen to death). There’s 
little point in trying to keep it, or this group, alive. That’s sad, 
because there is a lot of useful stuff in the FAQ.

The most constructive approach would be to write a new JavaScript FAQ, 
making use of the information in comp.lang.javascript but breaking any 
connection to this group, and to find a good home for it. By good home, 
I mean connecting it with an active, constructive forum.

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

[toc] | [prev] | [next] | [standalone]


#21727

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-10-25 21:51 +0200
Message-ID<8832895.sLtn3ilFtW@PointedEars.de>
In reply to#21610
Osmo Saarikumpu wrote:

> 15.10.2013 2:00, FAQ server kirjoitti:
>> * use of an unsafe name: http://jibbering.com/names/
> 
> 404.

Try <http://PointedEars.de/faq/names> instead.

The error has been fixed in <http://PointedEars.de/faq>.  Thank you.
 
-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#21720

FromKale <kalezwe@gmail.com>
Date2013-10-24 20:10 -0700
Message-ID<a73048b5-5571-428d-ba70-3e0e9918a513@googlegroups.com>
In reply to#21609
Try 
var snurgleEl = document.getElementById("snurgle").innerHTML; 
alert(snurgleEl); 

-Kale

[toc] | [prev] | [next] | [standalone]


#21729

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-10-25 22:36 +0200
Message-ID<2241616.lPyINzS4Il@PointedEars.de>
In reply to#21720
Kale wrote:

> Try
> var snurgleEl = document.getElementById("snurgle").innerHTML;
> alert(snurgleEl);

Have you *read* the FAQ entry?

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web