Rick Donohoe
Rick Donohoe

Reputation: 7271

What does '>' mean when used as a JQuery selector?

Apologies if this is a stupid question but it is quite hard to find using a search engine, but what does the '>' operator mean when used as a selector?

E.g.

$('div.form-input > label')....

Upvotes: 1

Views: 184

Answers (7)

qwertyboy
qwertyboy

Reputation: 1646

It's parent > child - select all elements matching the second selector that are children of elements matching the first selector. For example:

div.myclass > p.yourclass

will select all p's of yourclass that are inside a div of myclass.

Upvotes: 5

Kivylius
Kivylius

Reputation: 6567

jQuery('parent > child')

Description: Selects all direct child elements specified by "child" of elements specified by "parent".

http://api.jquery.com/child-selector/

Upvotes: 4

dotty
dotty

Reputation: 41473

It's the child selector. See more here.

Upvotes: 3

wirey00
wirey00

Reputation: 33661

It selects the child of a div with class "form-input" that is a label. You can read more about child selector here http://api.jquery.com/child-selector/

Upvotes: 3

jbrtrnd
jbrtrnd

Reputation: 3843

div.form-input > label selector will match the direct label descendant of the div.form-input

Upvotes: 1

xdazz
xdazz

Reputation: 160883

It is same with css selector, select for the direct child.

Upvotes: 3

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 299048

The same as in CSS, a label directly inside a div with class form-input

$('div.form-input label') // label can be anywhere inside the div

$('div.form-input > label') // label must be directly inside the div (at top level)

Upvotes: 5

Related Questions