Reputation:
I have a markup like this:
<div class="container">
<div>one</div>
<div>two</div>
<div>three</div>
<div>four</div>
<div>five</div>
</div>
I want to give background color using jQuery index()
for any div
inside the container (I will get indexes dynamically from the server).
Upvotes: 1
Views: 163
Reputation: 74738
Try with .eq()
and :eq()
:
$('.container div').eq(idx).css('background','purple');
$('.container div:eq('+idx+')').css('background','purple');
Upvotes: 2