例如假設您具備以下條件:你可以「和」jQuery選擇器在一起嗎?
<div id=1 class="a b c">...
<div id=2 class="b y c">...
<div id=3 class="b y x">...
<div id=4 class="c b">...
<div id=5 class="x 1 y">...
我怎麼會選擇具有class="b"
和class="c"?
我在尋找那只是標識div的id=1, 2, and 4.
例如假設您具備以下條件:你可以「和」jQuery選擇器在一起嗎?
<div id=1 class="a b c">...
<div id=2 class="b y c">...
<div id=3 class="b y x">...
<div id=4 class="c b">...
<div id=5 class="x 1 y">...
我怎麼會選擇具有class="b"
和class="c"?
我在尋找那只是標識div的id=1, 2, and 4.
謝謝Joe。 -shakes- head我儘可能快地學習jQuery,它不斷讓我感到驚訝,它有多容易。當存在簡單的問題時,我傾向於尋找複雜的解決方案。總結:ANDing選擇器:$(
即:ANDing選擇器:將選擇器彼此相鄰。 ORing選擇器:用逗號分隔選擇器。簡單。再次感謝你。 –
演示:http://jsfiddle.net/BEGZy/2/ –
就像你會用CSS做:
$(".b.c").whatever()
正如一個音符,以數字開頭的類不會,如果你嘗試的風格他們的工作。對於JQuery,我從來沒有嘗試過。我只想告訴你。 –
哦,上帝,他問我確切的最後一次採訪問題:) $('。b')。each(function(){$(this)hasClass('.a')// if condition yes - do your process} –
@ Anand,看看Joe的回答,祝你工作順利:) –