:last-childS2C 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 Examplego to top of page 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:

go to home page Homepage go to top of page Top