On 21/04/2006 09:09, Marc wrote:
Considering the following list how do I get a reference to the ul just below
the li with id products? [...]
<ul>
<li id="products">products</li>
<ul>
With potential difficulty. The markup is invalid, so how a browser
constructs the document tree is entirely dependant upon its error
correction mechanism. Any of the following are feasible results:
- <ul>
<li id="products">products
<ul> <!-- This is what the markup
should look like.
-->
- <ul>
<li id="products">products</li>
</ul>
<ul>
- <ul>
<li id="products">products</li>
<li> <!-- This would be a new list item. -->
<ul>
- <ul>
<li id="products">products</li>
<li id="child">child
<ul>
A browser might even tolerate the invalid markup, as-is. In any case,
one cannot hope for predictable behaviour with something that is
fundamentally broken. Fix the markup then - as has already been
suggested - use a loop (with the children [childNodes] of the 'products'
list item, in this case) until a list element is encountered.
[snip]
Mike
--
Michael Winter
Prefix subject with [News] before replying by e-mail.