2012-10-25 82 views
0
<span class="one"> 
    <span class="two"> 
     <span class="Three"> 
       <span class="Four"> 
       <a href=''>1</a> 
       <a href=''>2</a> 
       <a href=''>3</a> 
       </span> 
     </span> 
    </span> 
</span> 

我想從span class="one" 選擇第一個a標籤這是一個正確的語法?jQuery的過濾器/選擇器

$('span.one > a:firstchild') 

感謝

+0

要選擇「span.one」的直接子還是「1」 這一個 – YogeshWaran

回答

2

嘗試。您在第一個和子女之間錯過了-。這是訪問直接子

$('span.one > a:first-child') 

參考:first-child

OR

你想從span.one

$('span.one a:first-child') 
2

使用a:first-child選擇a內span.four或a:first都應該工作

$('span.one a:first-child'); //or 
$('span.one a:first')