:nth-of-type() Selector

nth-of-type selector

Description: Selects all elements that are the nth child of their parent in relation to siblings with the same element name.

  • version added: 1.9jQuery( ":nth-of-type(index/even/odd/equation)" )

    index: The index of each child to match, starting with 1, the string even or odd, or an equation ( eg. :nth-of-type(even), :nth-of-type(4n) )

Because jQuery's implementation of :nth- selectors is strictly derived from the CSS specification, the value of n is "1-indexed", meaning that the counting starts at 1. For other selector expressions such as :eq() or :even jQuery follows JavaScript's "0-indexed" counting.

Further discussion of this usage can be found in the W3C CSS specification.


Find each span that is second in relation to its sibling spans.

<!doctype html>
<html lang="en">
  <meta charset="utf-8">
  <title>nth-of-type demo</title>
  .nth {
    color: red;
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
$( "span:nth-of-type(2)" )
  .append( "<span> is 2nd sibling span</span>" )
  .addClass( "nth" );


© The jQuery Foundation and other contributors
Licensed under the MIT License.