JQ Home  <<  Filtering  <<  .last()

Filter last element.

Description

The .last() method is used to reduce the matched set to the last element.

Syntax

Signature Description
.last()Reduce the matched set to the last element.

Parameters

None

Return

A jQuery object containing the last element of the matched set.

.last() Method Example Filtering  <<  Top

Reduce the matched set to the last element.

In the example below we select all 'td' elements within the table with the class of 'testtable' and then reduce the matched set to the last element.


Table For Testing The .last() Signature
Table Row 1, Table Data 1 Table Row 1, Table Data 2
Table Row 2, Table Data 1 Table Row 2, Table Data 2



$(function(){
  $('#btn2').on('click', function() {
    $('.testtable td').last()
                      .css('backgroundColor', 'orange');
  });
});


Press the button below to action the above code:

Related Tutorials

jQuery Intermediate Tutorials - Lesson 1 - Filtering Elements