jQueryThe nth-child selector is used to select the nth child tag of its parent tag. Itsindexstarts from 1, that is, n starts from 1, not from 0.
For example:
1 $(‘tr:nth-child(3)’) —Select the third tr child element in the tr parent tag element.
2 $(‘tr:nth-child(3n)’)—Select the tr child tag element at the 3rd multiple position in the tr parent tag.
3 $(‘tr:nth-child(even)’)—Selects all even-numbered tr child elements in the tr parent tag.
jquery Example
A simple example is used to illustrate nth-childFunctionDynamicly change the background color of thetablerow.
jquery nth-child example jquery nth-child example
row 1 |
row 2 |
row 3 |
row 4 |
Row #5 |
Row #6 |
Row #7 |
Row #8 |
Row #9 |
Row #10 |
lt;/html>
Effect:
Click button 1:
##Click button 2 Click button 3: Click button 4:The above is the detailed content of The selector for selecting child elements in jquery is the nth-child selector. For more information, please follow other related articles on the PHP Chinese website!