jQuery :first-of-type Selector

Last Updated Jul 21, 2015, 12:00:06 PM





jQuery :first-of-type Selector

jQuery :first-of-type selector used to select the first of type element if there are more than one element in the same parent.

Syntax

When there are multiple elements with the same content or same value, jQuery :first-of-type selector will select the first element of its type

Example

It will find the first span in each matched div and add a class to it.


In the above HTML code we have the span element Tom 4 times in the first parent and in the second div we have Rupee span element 3 times. Using the below jQuery :first-of-type selector we can select the first occurance of Tom, Rupee and apply blue color to both.


Output
jQuery first-of-type selector

Try It Now

All jQuery Child Selectors

Other Advanced jQuery Selectors you might want to learn
jQuery Complete Selectors Reference

jQuery Selectors

jQuery Basic Selectors

jQuery Child Selectors

jQuery Content Filter Selectors


Sources and Credits

The content and methods in the tutorial has been referred and updated with jQuery API and The jQuery Foundation

Last Updated Jul 21, 2015, 12:00:06 PM