返回值:Array<Element(s)> :first-child
V1.1.4 概述
匹配所給選擇器 ( :之前的選擇器) 的第一個子元素
類似的 :first 匹配第一個元素,但是:first-child選擇器可以匹配多個:即為每個父級元素匹配第一個子元素。這相當於:nth-child(1)
示例
描述:
在每個 ul 中查詢第一個 li
HTML 程式碼:
<ul>
<li>John</li>
<li>Karl</li>
<li>Brandon</li>
</ul>
<ul>
<li>Glen</li>
<li>Tane</li>
<li>Ralph</li>
</ul>
jQuery 程式碼:
$("ul li:first-child")
結果:
[ <li>John</li>, <li>Glen</li> ]