how to choose only the third (
Use the eq method as follows:
$('li').eq(2).css('background', 'yellow');
Or you can use this filter selector option :eq :
$('li:eq(2)').css('background', 'yellow');
Indexing starts at 0 , you need to specify 2 to actually select the third li
If you want to select every third element, you need to use nth-child as follows:
$('li:nth-child(3n)')
The nth-child index starts at 1 .
Sarfraz
source share