:last-child選擇器選取屬于其父元素的最后一個子元素。
使用:first-child選擇器來選取屬于其父元素的第一個子元素。
$(":last-child")選擇屬于其父級的最后一個子級的每個<p>元素:
$(document).ready(function(){
$("p:last-child").css("background", "coral");
});測試看看?/?選擇所有<div>元素中的最后一個<p>元素:
$(document).ready(function(){
$("div p:last-child").css("background", "coral");
});測試看看?/?