首頁  >  選擇器  > :last-child

返回值:Array<Element(s)>:last-child

V1.1.4jQuery :last-child 選擇器概述

匹配最后一個子元素

:last 只匹配最后一個元素,而此選擇符將為每個父元素匹配最后一個子元素

示例

描述:

在每個 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:last-child")
結果:
[ <li>Brandon</li>, <li>Ralph</li> ]