Using> in jquery selector

Possible duplicate:
What does it mean a > b?

Hi, can anyone tell me what this selector style is used for?

$("> div", "#main-content")

this is the same as

 $("div", "#main-content")

?

I have not seen this style before and just stumbled upon it in the template I just bought.

+5
source share
6 answers

There are some excellent answers above. To specifically answer your question:

How jQuery structure works: $("tagToSelect", "context") which can also be expressed as $("context tagToSelect")

">" selects only tags immediately inside the context (at the same level)

So, $("> div", "#main-content") technically the same as $("#main-content > div") selecting all divs that are the same level in # main-content (but not deeper)

: $("div", "#main-content") , $("#main-content div") DOM divs

, : -)

+2

> , . > , .

:

<div id="A">
  <div id="B">
    <div id="C"></div>
  </div>
</div>

:

#A > #B

B,

#A > #C

C,

#A #C

.

+4

, $("div", "#main-content") #main-content, $("> div", "#main-content") . . docs.

+2

child - selects only direct children
just try again:

Note. The $ selector ("> elem", context) will be deprecated in a future release. Its use is thus discouraged instead of using alternative selectors.

+2
source

> used for direct children.

<ul id="mainUl">
   <li>
      <ul id="secondaryUl">
         <li></li>
      </ul>
   </li>
</ul>

Here the tags <ul>will be caught using $("ul"), but #mainUlwill only be caught using$("> ul")

+1
source

All Articles