:last
** DEPRECATED **
JQ Home <<
Selectors <<
:last
Last element match selector.
Shorthand version $(':last')
Description
The :last
selector, selects the last matched element.
- Being a jQuery extension the
:last
pseudo selector is not part of any current CSS specification. Therefore:last
cannot take advantage of the performance boost provided by the native DOMquerySelectorAll()
method.
This method was deprecated in jQuery 3.4.
Syntax
Signature | Description |
---|---|
jQuery(':last') | Last element match |
Parameters
None.
Return
N/A.
:last
Examples
Selectors << Top
Selects last matched element.
In the example below we apply an orange background to last 'td' element of the tables marked with a class of 'jskeywordtable'.
So the table below will be selected but the Syntax table above will not.
Table Row 1, Table Data 1 | Table Row 1, Table Data 2 |
Table Row 2, Table Data 1 | Table Row 2, Table Data 2 |
Table Row 3, Table Data 1 | Table Row 3, Table Data 2 |
Table Row 4, Table Data 1 | Table Row 4, Table Data 2 |
$(function(){
$('#btn1').on('click', function() {
$(".jskeywordtable td:last").css('backgroundColor', 'orange');
});
});
In the example below we apply a green background to last 'input' element.
So the button below will be selected but the button above will not.
$(function(){
$('#btn2').on('click', function() {
$('input:last').css('backgroundColor', 'green');
});
});
Related Tutorials
jQuery Basic Tutorials - Lesson 4 - jQuery Selectors