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

First of child type selector.

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


The :first-of-type selector, selects the first element types that have no other element with both the same parent and the same element name coming before 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(':first-of-type')First of child type selector match





:first-of-type ExampleTop

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

The following example will check for the first 'h2' element within the document (the heading at the start of the main content section) and turn the background colour yellow.

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

Press the button below to action the above code: