:last-of-type選擇器選擇所有元素,這些元素是其父元素的特定類型的最后一個子元素。
這與:nth-last-of-type(1)相同。
使用:first-of-type選擇器可以選擇所有元素,它們是其父元素的特定類型的第一個子元素。
$(":last-of-type")
選擇屬于其父級的最后一個<p>元素的每個<p>元素:
$(document).ready(function(){ $("p:last-of-type").css("background", "coral"); });測試看看?/?
選擇所有<div>元素中的最后一個<p>元素:
$(document).ready(function(){ $("div p:last-of-type").css("background", "coral"); });測試看看?/?