jQuery last() get last from selected elements

Description

jQuery last() get last from selected elements

View in separate window

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

<h1>Welcome to My Homepage</h1>

<p>My <span>name</span> is CSS.</p>
<p>This is a <span>test</span>.</p>
<p>This <span>is</span> another test.</p>

</body>
</html>



PreviousNext

Related