Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > <ul>s nested in <li>s - how to get the on on higher level ?

Reply
Thread Tools

<ul>s nested in <li>s - how to get the on on higher level ?

 
 
abs
Guest
Posts: n/a
 
      05-17-2005
Anybody has an idea how to get the <ul> element which is not nested in <li>
element ? In other words I have several lists like this:

<ul id="1">
<li>Aaaaaaaa</li>
<li>Bbbbbbbb</li>
<li>Cccccccc
<ul>
<li>111111</li>
<li>222222</li>
<li>333333
<ul>
<li>@@@@@@@@@</li>
<li>{{{{{{{}</li>
<li>????>>>>></li>
</ul>
</li>
</ul>
</li>
</ul>

<ul id"2">
<li>qqq</li>
<li>vvvv</li>
</ul>

and I want to get the <ul>s which have id "1" and "2" in this example but I
can't use ids to get them.

Best regards,
ABS


 
Reply With Quote
 
 
 
 
RobB
Guest
Posts: n/a
 
      05-17-2005
abs wrote:
> Anybody has an idea how to get the <ul> element which is not nested

in <li>
> element ? In other words I have several lists like this:
>
> <ul id="1">
> <li>Aaaaaaaa</li>
> <li>Bbbbbbbb</li>
> <li>Cccccccc
> <ul>
> <li>111111</li>
> <li>222222</li>
> <li>333333
> <ul>
> <li>@@@@@@@@@</li>
> <li>{{{{{{{}</li>
> <li>????>>>>></li>
> </ul>
> </li>
> </ul>
> </li>
> </ul>
>
> <ul id"2">
> <li>qqq</li>
> <li>vvvv</li>
> </ul>
>
> and I want to get the <ul>s which have id "1" and "2" in this example

but I
> can't use ids to get them.


Hmm...very mysterious. Oh, well...any chance we could see the rest of
your document structure - not just that subtree?

var i = 0,
ul,
unnested_uls = [],
all_uls = document.getElementsByTagName('ul');
while (ul = all_uls.item(i++))
if (null == ul.getElementsByTagName('ul'))
unnested_uls.push(ul);

....should get you a collection of them.

http://www.webreference.com/programm.../chap17/7.html

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      05-17-2005
abs wrote:
> Anybody has an idea how to get the <ul> element which is not nested in <li>
> element ? In other words I have several lists like this:
>
> <ul id="1">


An id should start with a letter, though it may contain numbers and
some other characters.

<URL:http://www.w3.org/TR/html401/types.html#type-name>

> <li>Aaaaaaaa</li>
> <li>Bbbbbbbb</li>
> <li>Cccccccc
> <ul>
> <li>111111</li>
> <li>222222</li>
> <li>333333
> <ul>
> <li>@@@@@@@@@</li>
> <li>{{{{{{{}</li>
> <li>????>>>>></li>
> </ul>
> </li>
> </ul>
> </li>
> </ul>
>
> <ul id"2">


<ul id="2">

> <li>qqq</li>
> <li>vvvv</li>
> </ul>
>
> and I want to get the <ul>s which have id "1" and "2" in this example but I
> can't use ids to get them.
>
> Best regards,
> ABS
>
>


Add this button to your page:

<input type="button" value="Click me" onclick="
var uls = document.getElementsByTagName('ul');
var i = uls.length;
while (i--){
if ( 'LI' != uls[i].parentNode.nodeName) {
alert('found ' + uls[i].id);
}
}
">

If you don't want to use getElementsByTagName, you could just walk
down the DOM tree, but that is getting really silly.


--
Rob
 
Reply With Quote
 
RobB
Guest
Posts: n/a
 
      05-17-2005
RobB wrote:
> abs wrote:
> > Anybody has an idea how to get the <ul> element which is not nested

> in <li>
> > element ? In other words I have several lists like this:
> >
> > <ul id="1">
> > <li>Aaaaaaaa</li>
> > <li>Bbbbbbbb</li>
> > <li>Cccccccc
> > <ul>
> > <li>111111</li>
> > <li>222222</li>
> > <li>333333
> > <ul>
> > <li>@@@@@@@@@</li>
> > <li>{{{{{{{}</li>
> > <li>????>>>>></li>
> > </ul>
> > </li>
> > </ul>
> > </li>
> > </ul>
> >
> > <ul id"2">
> > <li>qqq</li>
> > <li>vvvv</li>
> > </ul>
> >
> > and I want to get the <ul>s which have id "1" and "2" in this

example
> but I
> > can't use ids to get them.

>
> Hmm...very mysterious. Oh, well...any chance we could see the rest of
> your document structure - not just that subtree?
>
> var i = 0,
> ul,
> unnested_uls = [],
> all_uls = document.getElementsByTagName('ul');
> while (ul = all_uls.item(i++))
> if (null == ul.getElementsByTagName('ul'))
> unnested_uls.push(ul);
>
> ...should get you a collection of them.
>
>

http://www.webreference.com/programm.../chap17/7.html

Eesh...early morning here. Never mind.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
c is a low-level language or neither low level nor high level language pabbu C Programming 8 11-07-2005 03:05 PM
Accessing higher security level from higher security level nderose@gmail.com Cisco 0 07-11-2005 10:20 PM
HyperLink.NavigateUrl always adds an extra ../ when going to a higher level directory Nathan Sokalski ASP .Net 0 05-29-2005 11:33 PM
Going from higher security level interface to lower security interface- HELP!!! - AM Cisco 4 12-28-2004 09:52 PM



Advertisments