JQuery Selector last

From CoderLearner
Jump to: navigation, search

Description

Select the last element and it only selects a single element. To select all matches elements use $(':last-chid').

Syntax

$(':last')

$('li:last')

$('td:last')

$('span:last')

Example 1

<!DOCTYPE html>
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Select</title>
      <script 
         type="text/javascript" 
         src="/lib/jquery-1.7.2.min.js">				 
      </script>

      <script>
         $().ready(function() {
            $('table tr:last').css('background-color','red');
         });
      </script>
   </head>
   <body> 

      <table>
         <tr>
            <th>Group No</th>
            <th>Name</th>
            <th>Total</th>
         </tr>
         <tr>
            <td>1451</td>
            <td>Lake Group</td>
            <td>50003</td>
         </tr>
         <tr>
            <td>3451</td>
            <td>City Group</td>
            <td>5002543</td>
         </tr>
      </table>
   </body>
</html>

Try It