473,545 Members | 2,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Correct nesting of UL, OL, LI elements

Hi,

I'm looking for opinion/facts/arguments on the correct nesting of UL,
OL, & LI elements.

For example, this is what I want (unordered list):

* Item 1
* Item 2
* Item 3
* Item 3a
* Item 3b
* Item 3c
* Item 4

Now, in my markup, I can do (A) or (B), and they both work.

<!-- Markup (A) -->
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<ul>
<li>Item 3a</li>
<li>Item 3b</li>
<li>Item 3c</li>
</ul>
<li>Item 4</li>
</ul>
<!-- Markup (B) -->
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3
<ul>
<li>Item 3a</li>
<li>Item 3b</li>
<li>Item 3c</li>
</ul>
</li>
<li>Item 4</li>
</ul>
Now, I prefer, and think that Markup A, is the better representation
of the data... but... I can't find a spec, that dictates which one is
"officially " correct... (due in part to the fact that in old HTML
days, the closing tags were not needed... thus the confusion as to
"where" that closing tag goes, when nesting)

This gets very interesting in the JS/CSS world, trying to deal with
this...

If I generate Markup A, then get a reference to the LI element for
"Item 3", called say... foo then I ask for foo.followingSi bling, in
Mozilla, I get as expected, the UL element, but in IE, I get the LI
for "Item 4"... IE "moves" the UL node, to the .lastChild position of
the preceding LI element.

So, here's the questions...

1.) Which method (by vote, spec or whatever) is correct/better?
Method A or B?

2.) Based on (1), is the IE implementation a Bug, or a Feature?
Mozilla's?

3.) If you want to style the sub items, what CSS would you use for
Method A, or B... or does it matter?

PS I don't expect a unanimous answer to any of these, I'm just trying
to get a feel for how everyone else interprets how Nested Lists are
"supposed" to work.

Feb 16 '07 #1
6 2632
wrote on 16 feb 2007 in comp.lang.javas cript:
I'm looking for opinion/facts/arguments on the correct nesting of UL,
OL, & LI elements.
This has nothing to do with Javascript.

Please go elswhere.

I would suggest you search fot a html NG.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 16 '07 #2
This has nothing to do with Javascript.

Well, actually it does, because IE is creating a DOM, that doesn't
reflect my markup. What I want to know, is should I change my
markup?... just deal with the difference programatically , or is this
something that the MS developers should look at fixing... e.g. if the
markup is in format A, then the DOM reflects so, if it is in format B,
then the DOM should reflect this also.

It was in the JavaScript, that I found the behaviour difference, and
thus I posted here. In an HTML forum, I likely wouldn't find the same
talent as here. Many people can code HTML, less can do JavaScript.

Feb 16 '07 #3
st************* *@gmail.com wrote:
For example, this is what I want (unordered list):

* Item 1
* Item 2
* Item 3
* Item 3a
* Item 3b
* Item 3c
* Item 4

Now, in my markup, I can do (A) or (B), and they both work.

<!-- Markup (A) -->
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<ul>
<li>Item 3a</li>
<li>Item 3b</li>
<li>Item 3c</li>
</ul>
<li>Item 4</li>
</ul>
Look into the HTML specification what elements are allowed as child
elements of ul elements:
<http://www.w3.org/TR/html4/struct/lists.html#h-10.2>
That shows that only li elements are allowed as children of ul (and ol)
elements so what you have above is not valid HTML 4.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 16 '07 #4
On Feb 16, 4:18 pm, stephen.cunli.. .@gmail.com wrote:
I'm looking for opinion/facts/arguments on the correct nesting
of UL, OL, & LI elements.
The HTML specification is the place to look for facts, and arguments
about it are best sought in a mark-up newsgroup.
For example, this is what I want (unordered list):

* Item 1
* Item 2
* Item 3
* Item 3a
* Item 3b
* Item 3c
* Item 4

Now, in my markup, I can do (A) or (B), and they both work.
This is "work" in one of the looser senses of the word.
<!-- Markup (A) -->
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<ul>
<li>Item 3a</li>
<li>Item 3b</li>
<li>Item 3c</li>
</ul>
<li>Item 4</li>
</ul>

<!-- Markup (B) -->
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3
<ul>
<li>Item 3a</li>
<li>Item 3b</li>
<li>Item 3c</li>
</ul>
</li>
<li>Item 4</li>
</ul>

Now, I prefer, and think that Markup A, is the better
representation of the data... but... I can't find a spec,
that dictates which one is "officially " correct...
That would be the HTML specification. The First is invalid as UL and
OL may only have LI children and their opening and closing tags are
not optional (so an opening UL/OL cannot imply the closing of an open
UL/OL).
(due in part to the fact that in old HTML
days, the closing tags were not needed...
Some closing tags are still not needed in HTML 4.01, and many more can
be omitted in reality (with inconsistent consequences).
thus the confusion as to
"where" that closing tag goes, when nesting)

This gets very interesting in the JS/CSS world, trying to
deal with this...
Structurally valid mark-up results in the creation of structurally
consistent, and predictable, DOMs. Error correcting invalid mark-up
does not. It is easier to script a document when the DOM being
scripted is of a predictable structure, so for scripting documents
should be structurally valid (which is true of all formally valid HTML
documents).
If I generate Markup A, then get a reference to the LI
element for "Item 3", called say... foo then I ask for
foo.followingSi bling,
You mean - foo.nextSibling -?
in Mozilla, I get as expected, the UL element, but in IE,
I get the LI for "Item 4"... IE "moves" the UL node, to
the .lastChild position of the preceding LI element.
And the next browser you try will likely do something else again.
So, here's the questions...

1.) Which method (by vote, spec or whatever) is correct/better?
Method A or B?
By spec, A is invalid and B is valid.
2.) Based on (1), is the IE implementation a Bug, or a Feature?
Mozilla's?
Both are features. No specification could mandate how error-correction
is handled (if it is at all) and so however it is handled (or not)
cannot be criticised as incorrect; there is no definition of 'correct'
to measure against.
3.) If you want to style the sub items, what CSS would you
use for Method A, or B... or does it matter?
CSS that relies on DOM parent/child/descendant/sibling relationships
may be heavily affected by inconsistent DOM structures being created
following the use of structurally invalid mark-up.
PS I don't expect a unanimous answer to any of these, I'm
just trying to get a feel for how everyone else interprets
how Nested Lists are "supposed" to work.
If you don't interpret the required nesting by the HTML specification
then you will be shooting yourself in the foot as soon as you start
attempting to script the resulting DOM.

Richard.

Feb 16 '07 #5
Richard,

Thanks for your reply, what I missed in reading the DTD/spec, was the
"*" on the LI element, wher *=any element (I presume.. which would
include another UL)

I'm not sure how I missed that, but that explains it all for me now.


Feb 16 '07 #6
<st************ **@gmail.comwro te:
Thanks for your reply, what I missed in reading the DTD/spec,
was the "*" on the LI element, wher *=any element (I presume..
which would include another UL)
No, the "*" means zero or more occurences.
I'm not sure how I missed that, but that explains it all
for me now.
Unlikely. It seems like some information on the interpretation of DTDs
would be useful to you. I cannot recommend any URL as mine is all on
paper.

Richard.

Feb 19 '07 #7

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

Similar topics

0
1123
by: Bill C | last post by:
I'm new to this so... Is it possible to create a well formed schema with child elements or do I some how have to use xslt to nest elements within elements to produce my final xml result set. My current xml output looks like this... <OrderSubmit> <Customer>ABC Company</Customer> <AccountID>100313</AccountID> <CustomerPO />...
3
7130
by: Michael Hertz | last post by:
I have hundreds of samples of XML documents on my harddisc. But all of them lack the one or another feature of XML. Some XML documents have no attributes some others are rather flat (nesting level=2). Furthermore there are XML samples which do not have duplicate elements with only different attribute values or all with the same attributes. I...
1
1244
by: martin mollema | last post by:
I'm stuck with the following problem: I want to develop a namespace that consists of two (later possibly more distinct namespaces) These subnamespaces are the DC element set and a private extension. The naming convention is DC:elementName and OVERHEID:otherElementName. In order ease the processing of these two element sets, I would like to...
4
1006
by: jetobe | last post by:
Hi everyone, I am trying to debug someone's site which has <h3><a href="www.legislation.qld.gov.au">Queensland Acts</a></h3> The problem is that the <a> tag is taking precedence and overriding the <h3> tags that they want the text to resemble. It's problematic because it's a huge site (around 500 pages), it's in
8
1743
by: Harlan Messinger | last post by:
I just read the note under the XHTML spec (http://www.w3.org/TR/xhtml1/#h-4.9) that explains how XML DTD notation doesn't provided for the exclusion of elements from containment by the element being defined. For example, there is no way to indicate that an <a> element can't contain another one. I see that the strict HTML DTD shows -(A)
4
2766
by: Henk | last post by:
Hi group! What is the use of nesting DIV's? Henk
3
2249
by: lawrence | last post by:
This is a follow up question to the conversation that started here: http://groups.google.com/groups?hl=en&lr=&safe=off&selm=da7e68e8.0410010901.18a813c9%40posting.google.com I tried nesting all my links in lists in UL's that were in a UL. I hate the result for its lack of consistency. Any design tips? How can I had headlines to my...
3
2691
by: shaun roe | last post by:
I have a document about 4 levels deep and in my XSLT I want to generate a unique string ID for each basic element based on its path through the hierarchy. If I use recursion, I am continually accessing the root element ID, here is a typical call: <xsl:variable name="fullPath"...
3
3154
by: Philipp Schumann | last post by:
Hi, I have several nested layers of <node> element that are processed by an XSLT template. Is there any possibility to determine the depth of a node in the overall nesting hierarchy? For example, I would like to obtain 0 for the root <node> tag; 1 for all child <node> tags; 2 for all tags that are child <node> tags of all previous <node>...
0
7490
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7682
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7935
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6009
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5069
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3465
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.