Last (:last)

Description and Syntax

$(':last)

selects the last element within the matched set.

Examples

  • $('li:last) selects the last <li> element
  • $('.myclass:last) selects the last element with the class myclass

The following code selects the last row.


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!-- w w w .jav a 2  s .co  m-->
           $("tr:last").css({backgroundColor: 'yellow', fontWeight: 'bolder'});
        });
    </script>
  </head>
  <body>
    <body>
    <table>
        <tr><td>First</td></tr>
        <tr><td>Middle</td></tr>
        <tr><td>Last</td></tr>
    </table>
    </body>
</html>

Click to view the demo

The code above generates the following result.

Last (:last)