jQuery :last-of-type Selector


The :last-of-type selector in jQuery is used to select all elements that are the last child of a particular type of their parent.

Syntax

The syntax is as follows −

$(":last-of-type")

Example

Let us now see an example to implement the jQuery :last-of-type Selector −

<!DOCTYPE html>
<html>
<head>
<style>
   .one {
      color: white;
      background-color: green;
      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-of-type").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>

Output

This will produce the following output −

raja
Published on 05-Nov-2019 10:43:33
Advertisements