If my original function was:
document.getElementsByClassName(\'blah\')[9].innerHTML = \'blah\';
...how would I change that so I get that sa
try the following
$('.blah').eq(9).html('blah');
See what you are looking for is :eq()
:
$('.blah').eq(9).html('blah');
because :eq()
is 0
indexed,so :eq(9)
will find the item at 10th index.
.eq() jQuery doc
There is :nth-child()
function too:
$('.blah:nth-child(10)').html('blah');
because :nth-child()
is 1
indexed so you have to give place 10th position there.
:nth-child() jQuery doc
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. Given a single containing two
- s, $('li:nth-child(1)') selects the first
- while $('li:eq(1)') selects the second.