:last-of-type JQ Home  <<  Selectors  <<  :last-of-type

Last of type child selector.

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


The :last-of-type selector matches 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 Example Selectors  <<  Top

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

The following example will check for the last 'h3' element that are the last among siblings within the document and turn the background colour yellow.

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

Press the button below to action the above code:

Related Tutorials

jQuery Basic Tutorials - Lesson 3 - CSS Selectors