jQuery: 最後一個選擇器
jQuery 中的 :last 選擇器用於選擇最後一個元素。
語法
語法如下 −
$(":last")示例
現在讓我們看一個示例來實現 jQuery :last 選擇器 −
<!DOCTYPE html>
<html>
<head>
<style>
.one {
color: black;
background-color: orange;
font-size: 16px;
border: 2px blue solid;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p:last").addClass("one");
});
</script>
</head>
<body>
<h1>Examination Details</h1>
<p>Date: 25th October 2019</p>
<p>Timings: 10AM TO 1PM</p>
<p>All the best for exams!</p>
</body>
</html>輸出
這將產生以下輸出 −

廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP