JQuery Selector last-child

From CoderLearner
Jump to: navigation, search

Description

Select all elements that are the last child of the given parent element. This selector can match more than one.

Syntax

$(':last-child');

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() {
            $('span:last-child').css('border','2px solid red');
         });
      </script>
   </head>
   <body>
      <div id="master">
         <span>One</span>
         <span>Two</span>
         <span>Three</span>
         <span>Four</span>
      </div>
      <div>
         <div id="inner">
            <span>Teacher</span>
            <span>Professor</span>
            <span>Student</span>
            <span>Employee</span>
         </div>
      </div>
   </body>
</html>

Try It