last() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:last

Description

The last() method returns the last element of the selected elements.

Syntax

The following code shows how to Select the last <p> element inside the last <div> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("p span").last().css("background-color", "yellow");
});//from www  .j  a  va 2s . c o m
</script>
</head>
<body>

<p>My <span>name</span> is span.</p>
<p>tutorial from <span>java2s.com</span>.</p>
<p>tutorial from <span><b>java2s.com</b></span>.</p>

</body>
</html>

Related Tutorials