Jan Hendrik Mangold wrote:
> On Jan 22, 2007, at 10:02 AM, John Resig wrote:
>
>> This was just fixed in 1.1.1, please upgrade and try it again.
>> http://jquery.com/blog/2007/01/22/jquery-111/
>
> In FF1.5.0.9 @ Mac OS X 10.4.7
>
> jquery 1.1.1
>
> <p id='para'>This is the target for my action
> <ul id='counter'>
> <li>one</li>
> <li>two</li>
> <li>three</li>
> </ul>
> </p>
>
> <ul id='color'>
> <li>red</li>
> <li>green</li>
> <li>blue</li>
> </ul>
>
> The following works
>
> $('li') => [<li>,<li>,<li>,<li>,<li>,<li>]
> $('ul') => [<ul id="counter">,<ul id="color">]
> $('#para') => [<p id="para" style="overflow: hidden; display: block;
> opacity: 0.930371;">]
>
> Now
>
> $('li',$('#counter')) => [<li>,<li>,<li>]
>
> but why
>
> $('ul',$('#para')) => []
>
> shouldn't it return the one ul element that is a child of #para? Also
>
> $('li',$('#para')) => []
>
> should return all the li elements under #para, but it doesn't
>
> Is my understanding of $() selectors wrong?
No, but your understanding of HTML is. A paragraph must not contain
other block level elements, e.g. ul, ol, div etc.
What happens is that a browser's HTML tag soup parser will implicitly
close the paragraph before the incorrectly nested ul starts:
<p id='para'>This is the target for my action</p>
<ul id='counter'>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
For the same reason you can leave away the closing </p> tag in HTML 4
(or vice versa, because you don't need the closing tag, the parser works
that way):
<p>One
<p>Two
<p>Three
Do not script on top of an invalid DOM tree, you cannot rely on anything
you might assume.
-- Klaus
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/