:nth-child(index/odd/even/equation)
This
will match all elements that are the nth-child of their parent or that are the
parent's even or odd children. While :eq(index) matches only a single
element, this matches more than one: One for each parent with index. Multiple
for each parent with even, odd, or equation. The specified index is
one-indexed, in contrast to :eq() which starts at zero.
$("ul li:nth-child(2)")
:first-child
It
will find all the elements that are the first child of their parent. There is a
confusion between :first and :first-child. While :first matches
only a single element :first-child matches all the first elements, one for each
parent.
$("div input:first-child")
This
finds the first input elements in each matched div element. Suppose
there are 3 text boxes in each div. Then the first text box of each div will be
selected. That means in total 3 text boxes will be selected or matched.
:last-child
It
will find all the elements that are the last child of their parent. There is a
confusion between :last and :last-child. While :last
matches only a single element :last-child matches all the last elements,
one for each parent.
$("div input:last-child")
This
finds the last input elements in each matched div element. Suppose there
are 3 text boxes in each div. Then the last text box of each div will be
selected. That means in total 3 text boxes will be selected or matched.
:only-child
This
finds all the elements which are only child of their parent. If their parent
has more than one elements inside them then none will be matched.
$("div button:only-child")
Suppose
there are 3 divs. First div contains no button, Second div contains only one
button and the third div contains more than one button. Then the button in the
second div will be matched.