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>

輸出

這將產生以下輸出 −

更新於: 05-Nov-2019

136 次瀏覽

開啟您的 職業生涯

完成課程並獲得認證

開始學習
廣告
© . All rights reserved.