Reputation: 7418
Something like
$('.mydiv' :eq(n) 'img')
but yeah that is a terrible way of writing it ah, help?
Upvotes: 0
Views: 282
Reputation: 56430
To show how it works with variable n:
$('.mydiv:eq('+n+') img')
You use + operator to concat in JavaScript.
Upvotes: 1
Reputation: 344547
You're almost there:
// Select all img elements in the 1st .mydiv:
$('.mydiv:eq(0) img')
// Select all img elements in the 3rd .mydiv:
$('.mydiv:eq(2) img')
See more examples of :eq()
at http://api.jquery.com/eq-selector.
To use a variable inside :eq
, do the following
// Select all img elements in the `n`th .mydiv:
$('.mydiv:eq('+n+') img')
Upvotes: 2