473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

abs
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
Jul 23 '05 #1
4 2179
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

Jul 23 '05 #2
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
Jul 23 '05 #3
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.

Jul 23 '05 #4
abs
Hi!

RobG wrote:
An id should start with a letter, though it may contain numbers and
some other characters.
Understood. But it was just an example :) I never use numeric ids :)
Add this button to your page: [...]
If you don't want to use getElementsByTagName, [...]


That's fine, I can use it. Thank you a lot for your help, I'll check it now
!

Best regards,
ABS
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: toylet | last post by:
Attached is some css codes for a website. It has 3 parts: top-bar, side-bar (on the left) and main-body. The top-bar has a mouseover menu called top-menu implemented via ul:hover. When the mouse...
19
by: CMAR | last post by:
I have the following markup. The problem is that the browser, e.g., IE6, inserts several lines of blank space between the <div> and the following table. Is there a way to minimize that vertical...
16
by: michael | last post by:
Is it possible to get all href URLs contained in a unordered list and place them in an array? Or in fact two different arrays, differently named one for each <ul> group? <ul> <li><a...
2
by: Shaun | last post by:
Hello! I have a quick question regarding CSS and having it applied to all elements. I am trying to eliminate the gap between a paragraph and a list that usually occurs in html and I've found...
6
by: ashkaan57 | last post by:
Hi, How can I set up the styling for different levels of <ULto use different images for bullets, be indenetd differently, ... Like: .. list 1 - item 1 - item 2 .. list 2
19
by: ashkaan57 | last post by:
Hi, I have a page in a right-to-left language and I am trying to make some bulleted lists using <ul>, but it puts the bullets to the left. Is there any way I can set the bullets to be on the...
5
by: Syl | last post by:
Hello experts!! The top menu navigation bar displays perfectly in IE, but does not display properly in Mozilla or Netscape : http://checkeredshirt.com/textonly.html For some reason the non-IE...
3
by: Man-wai Chang | last post by:
A 2 columns x 10 rows matrix input form <ul> <li> <ul> <li>item name 1 <li><input type="textbox" name="input_col_1_row_1"> <li><input type="textbox" name="input_col_1_row_2"> </ul> <li>
6
by: capricious | last post by:
Is it possible, so that when you do multiple <UL>'s to control how deep the UL's are marked? For example, it would defaultly look like this with multiple ULs and LIs: -- Code : Main...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.