aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes getElementsByTagName from nested list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "getElementsByTagName from nested list" Watch "getElementsByTagName from nested list" New topic
Author

getElementsByTagName from nested list

Howard Watson
Ranch Hand

Joined: Jan 07, 2004
Posts: 56
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

Joined: Jan 10, 2002
Posts: 61773
    
  67

Your code will be much easier to read and follow if you use UBB code tags. Please read this for more information.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61773
    
  67

document.getElementById('sitemap')
Your HTML contains no element with an id of sitemap.
Howard Watson
Ranch Hand

Joined: Jan 07, 2004
Posts: 56
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

Joined: Mar 06, 2005
Posts: 392
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

Joined: Jan 07, 2004
Posts: 56
This is a better example. unREM the nested UL and/or remove the body onload to duplicate.

Howard Watson
Ranch Hand

Joined: Jan 07, 2004
Posts: 56
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

Joined: Jan 07, 2004
Posts: 56
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getElementsByTagName from nested list