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

Last of type child selector.

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

Description

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.

Syntax


Signature Description
jQuery(':last-of-type')Last of type selector match

Parameters

None.

Return

N/A.

:last-of-type Examplego to top of page Top

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.


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

Press the button below to action the above code:


go to home page Homepage go to top of page Top