codeine24_7 — 2010-12-08T15:43:40-05:00 — #1
I get 0. However, I have three <li> in my document.
When I run
var listItems=document.getElementsByTagName("*") ;
I get a length of 5 in my alert (<html>, <head>, <title>, <meta>, <script>, ). I tested for these tags individually (e.g. getElementsByTagName("html");) and they are accounted for.
Why am I unable to target the body, ul, or list tags? I checked my document and it's essentially the same as the book's, except for the text between the elements.
What is it that I am missing?
system — 2010-12-08T15:58:50-05:00 — #2
codeine24_7 — 2010-12-08T16:06:56-05:00 — #3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
content="text/html; charset=utf-8" />
Sidney Crosby traded to Vancouver Canucks.
Ovechkin to sign long-term deal with Vancouver Canucks.
Canucks blow out Ducks 8-0.
var listItems = document.getElementsByTagName("li");
var numItems = listItems.length;
system — 2010-12-08T16:14:25-05:00 — #4
post the code exactly as it appears in canucks.js
you need to call the js to get the li elements after the document has finished loading and not before, or at least after the <li>'s have finished loading.
codeine24_7 — 2010-12-08T16:26:03-05:00 — #5
That is the only thing I have in canucks.js right now. The rest I put into comment tags since I was not sure if it was interfering with it.
How do I ensure that the li elements load first before being called?
system — 2010-12-08T16:30:02-05:00 — #6
just above the </body>
2) leave the call to canucks.js where it is in the <head> and change your code to
codeine24_7 — 2010-12-08T16:35:15-05:00 — #7
Thanks! I spent over an hour last night trying to figure out why it wasn't working. This is sweet relief.
system — 2010-12-08T16:41:48-05:00 — #8
codeine24_7 — 2010-12-08T16:45:17-05:00 — #9
paul_wilkins — 2010-12-08T20:48:03-05:00 — #10
Another solution instead of using Core.start is to move your script to the end of the body, just before the </body> tag. That way the rest of the body is available by the time the script does its thing.
However, for the sake of working in with the rest of the book, you should stick with using Core.start instead of other solutions.
codeine24_7 — 2010-12-09T01:31:02-05:00 — #11
paul_wilkins — 2010-12-09T01:41:34-05:00 — #12
Also, the errata can help to clear up some mistakes that made it in to the book.
codeine24_7 — 2010-12-09T01:48:36-05:00 — #13