Home >>jQuery Tutorial >jQuery :last-of-type Selector

jQuery :last-of-type Selector

jQuery :last-of-type Selector

jQuery :last-of-kind selector in jQuery is used to pick all items that are their parent's last child, of a particular type.

Syntax:
$(":last-of-type")
Here is an Example of jQuery :last-of-type Selector:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p:last-of-type").css("background-color", "orange");
});
</script>
</head>
<body>
<p>The first paragraph in body.</p>
<div style="border:1px solid;">
<p>The first paragraph in div.</p>
<p>The Second paragraph in div.</p>
</div><br>
<div style="border:1px solid;">
<p>The first paragraph in div.</p>
<p>The Second paragraph in div.</p>
<span>This is a span element.</span>
</div>
<p>The last paragraph in body.</p>
</body>
</html>

Output:

The first paragraph in body.

The first paragraph in div.

The Second paragraph in div.


The first paragraph in div.

The Second paragraph in div.

This is a span element.

The last paragraph in body.