Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between jQuery's space and > selectors?

What's the difference between the space and > selectors? And possibly related, how can I look for something that's the direct child of something else, and not lower down the descendant line?

like image 751
Eliyahu Avatar asked Aug 02 '09 03:08

Eliyahu


1 Answers

For:

<ul>
  <li>Item 1</li>
  <li>Item 2
    <ul>
      <li>Item 2.1</li>
      <li>Item 2.2</li>
    </ul>
  </li>
  <li>Item 3</li>
</ul>

For example

$("ul > li").addClass("blah");

adds class "blah" to 1 2 and 3 whereas:

$("ul li").addClass("blah");

add class "blah" to every list element.

I'm not sure what you're referring to with < and ? operators.

like image 113
cletus Avatar answered Oct 10 '22 01:10

cletus