2012-06-05 25 views
1

道歉,如果這是一個愚蠢的問題,但它很難找到使用搜索引擎,但'>'作爲選擇器使用時的意思是什麼?當用作JQuery選擇器時,'>'是什麼意思?

E.g.

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

子選擇器:http://api.jquery.com/child-selector/ – Blazemonger

+0

就像一個註釋,這個語法也適用於CSS。很多jQuery選擇器都基於CSS選擇器。 – roflmao

回答

5

它的父>子 - 選擇第二個選擇匹配的是第一選擇匹配的元素的兒童的所有元素。例如:

div.myclass > p.yourclass 

將選擇您的類的所有p在myclass的div內。

5

一樣CSS,直接一個div內的標籤與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) 
+0

爲58k代表答案它應該比「直接在裏面」 – Christoph

3

這是相同的CSS選擇器類,選擇直接孩子。

1

div.form-input > label選擇將匹配直接label後裔的div.form-input

3

這是child選擇器。查看更多here