Yes, but in this tree:

<ul class="nav">
  <li><a href="#"></a></li>
</ul>

both selectors will yield the same results, the point here is
performance.

@north the article is right. Sizzle processes the selector from right
to left, so explicit child relationships and simpler selectors will
make it faster. See for yourself (switch between versions under
"Source" on the left): http://jquery.nodnod.net/cases/474

cheers
ricardo

On Jun 30, 6:04 pm, "Cesar Sanz" <the.email.tr...@gmail.com> wrote:
> ".nav li a"  is very different to ".nav li > a"
>
> in the second statement (".nav li > a") only the anchors that are direct
> descendant of "li" elements will be chosen
> in the first statement (".nav li a" ) every anchor will be picked, direct or
> indirect descendant
>
> ----- Original Message -----
> From: "brian" <bally.z...@gmail.com>
> To: <jquery-en@googlegroups.com>
> Sent: Tuesday, June 30, 2009 11:45 AM
> Subject: [jQuery] Re: ul.nav a VS. .nav li > a
>
> > I can't speak for Sizzle but, if you'll only ever have one "nav"
> > element on a page, you're better off using an ID than a class.
>
> > On Tue, Jun 30, 2009 at 8:03 AM, north<ollo...@web.de> wrote:
>
> >> Hi,
>
> >> yesterday I read an article about jQuery performance. In one part the
> >> author talks about selectors and uses
>
> >> .nav li a
>
> >> as an example. He states that before jQuery 1.3., the selector
>
> >> ul.nav a
>
> >> would have been the best way to get all links in the list. In jQuery
> >> 1.3., due to the inclusion of Sizzle,
>
> >> .nav li > a
>
> >> "should" be the best way. He doesn't mention any speed tests though,
> >> and only briefly explains that the reason for this is Sizzle's way of
> >> walking through selectors from right to left.
>
> >> Can anyone confirm this "theory"?
>
> >> Thanks!

Reply via email to