Latest web development tutorials

jQuery :last-of-type 選擇器

jQuery 選擇器 jQuery選擇器

實例

選取屬於其父元素的最後一個<p> 元素的每個<p> 元素:

$("p:last-of-type")

嘗試一下»

定義和用法

:last-of-type 選擇器選取屬於其父元素的特定類型的最後一個子元素的所有元素。

提示:該選擇器與:nth-last-of-type(1)相同。

提示:請使用:first-of-type選擇器來選取屬於其父元素的特定類型的第一個子元素的所有元素。


語法

$(":last-of-type")


實例

嘗試一下- 實例

選取所有<div>元素的最後一個<p>元素
如何選取所有<div> 元素的最後一個<p> 元素。

:last、:last-child和:last-of-type之間的不同
演示:last、:last-child 和:last-of-type 選擇器之間的不同。


jQuery 選擇器 jQuery選擇器