:last-of-typeS2C Home « Selectors « :last-of-type

Last of type child selector.

Shorthand version  $(':last-of-type')


The :last-of-type selector, selects elements that have no other element with both the same parent and the same element name coming after it in the document tree.

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-of-type')Last of type selector match





:last-of-type ExampleTop

Selects all elements that are the last among siblings of the same element name.

The following example will check for the last 'h2' element within the document, which happens to be the first heading of the main content section above and turn the background colour yellow.

  $('#btn30').on('click', function() {
    $("h2:last-of-type").css('backgroundColor', 'yellow'); 

Press the button below to action the above code: