开发者

JQuery, Selecting every img in the n'th div with a specific class

开发者 https://www.devze.com 2023-01-01 14:46 出处:网络
Something like $(\'.mydiv\' :e开发者_如何学Goq(n) \'img\') but yeah that is a terrible way of writing it ah, help?You\'re almost there:

Something like

$('.mydiv' :e开发者_如何学Goq(n) 'img')

but yeah that is a terrible way of writing it ah, help?


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')


To show how it works with variable n:

$('.mydiv:eq('+n+') img')

You use + operator to concat in JavaScript.


$("div.myclass:eq(n) img")
0

精彩评论

暂无评论...
验证码 换一张
取 消