• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getElementsByTagName from nested list

 
Howard Watson
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The HTML and javascript below fails to grab the nested LIs. It works right up to the LI containing a nested UL. Can someone point me to understanding?

HTML:

JS:

[ July 02, 2007: Message edited by: Howard Watson ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code will be much easier to read and follow if you use UBB code tags. Please read this for more information.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
document.getElementById('sitemap')
Your HTML contains no element with an id of sitemap.
 
Howard Watson
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought there used to be a way to preview before posting, but I couldn't find it. And I forgot that all the leading white space would be stripped. Thanks for the reminder, Bear.

The markup and code I posted are snippets. The sitemap works. The id of sitemap is a div container. What I've been trying to do is populate the LIs using JavaScript with window.onload. The links populate an iFrame named 'docs'.



But I haven't been able to access the nested LIs.
 
Sri Anand
Ranch Hand
Posts: 392
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I faced this problem recently , getElementByTagname wasnt working, after debugging i found that one of the tags had no ending tag (Ul tag) and it did not recognize the tags below, try to check the struture visually in a editor if all the tags are closed properly . all the best
 
Howard Watson
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a better example. unREM the nested UL and/or remove the body onload to duplicate.

 
Howard Watson
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not realize that innerHTML was not part of any standard, just an old browser hack.

Testing with:


things work as expected.
[ July 09, 2007: Message edited by: Howard Watson ]
 
Howard Watson
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the answer was in my face and simple:

altering the innerHTML destroys and replaces the content of each li element. When it does this for the third li element, the unordered list and li elements nested within it no longer exist because they�ve been replaced with the new content {the new innerHTML)


codingforums

I guess innerHTML ain't broke after all. I am.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic