views:

27

answers:

3

Hey guys,

I'm still learning how to use Sizzle selector. So far I know this:

Sizzle('#blah') - searches the entire document for element(s) with id 'blah'.

Sizzle('.blah') - searches the entire document for element(s) with css class 'blah'.

Then today I found this:

Sizzle('> div') - searches entire document for elements of 'div' tags. (I could be wrong but that's what it is doing for me)

Which makes me ponder, what other syntax are there to search for stuff using Sizzle??

+2  A: 

The > is called child selector and is used to find direct/immediate children of parent elements.

Example:

<ul id="ul">
  <li>Child</li>
  <li>Child</li>
  <li>Child</li>
  <li>
      <ul>
         <li>Child Again</li>
         <li>Child Again</li>
         <li>Child Again</li>
      </ul>
  </li>
</ul>

Sizzle:

Sizzle('ul#ul > li')

In the above example, the child selector will only select direct children that is ones with text Child not Child Again

Sarfraz
To elaborate - the syntax that sizzle uses is a superset of [CSS selector](http://www.w3.org/TR/css3-selectors/) syntax.
Matt Ball
Thanks guys. @Bears thx for the link that's really helpful!
Gary
+1  A: 

pretty much any selector you can do with css3 you can do with sizzle.

Patricia
+1  A: 

Here's the official reference on which selectors Sizzle supports: http://wiki.github.com/jeresig/sizzle/. But, as has already been said, it's basically the same syntax as CSS3 selectors.


And here's the link the OP was apparently asking for: http://www.w3.org/TR/css3-selectors/

Matt Ball
Thanks, I read that document and it seemed confusing as they combined different patterns. I was looking for the list of "basic" patterns.
Gary
Thanks, your link to w3c's list of selector pattern in the other answer is what I was looking for.
Gary
@Gary: Are you actually using Sizzle directly, or are you using jQuery? I'm curious.
Matt Ball
@Bears: I'm just using Sizzle directly
Gary