:last-child JQ Home  <<  Selectors  <<  :last-child

Last child selector.

Shorthand version $(':last-child')


The (':last-child') selector, selects all last child elements of their parent.

If this selector is not preceded by another selector the universal selector ("*") is implied and so the whole DOM will be searched. Use another selector as in the example below to narrow the search and improve performance.


Signature Description
jQuery(':last-child')Last child match





':last-child' Example Selectors  <<  Top

Selects all last child elements of their parent.

This method calls JavaScript's getElementsByTagName() function 'under the hood' to return the appropriate elements when used.

The following example will select the last 'td' elements within 'tr' elements and change the background colour of these elements to yellow.

  $('#btn23').on('click', function() {
    $('tr td:last-child').css('backgroundColor', 'yellow');

Press the button below to action the above code:

Related Tutorials

jQuery Basic Tutorials - Lesson 3 - CSS Selectors