开发者

simple jquery class array

开发者 https://www.devze.com 2023-02-08 03:30 出处:网络
with the do开发者_如何转开发m, document.getElementsByClassName(\"myClass\")[2] selects the 3rd element of class myClass

with the do开发者_如何转开发m,

document.getElementsByClassName("myClass")[2]

selects the 3rd element of class myClass

in jQuery,

$('.myClass')

gets class myClass but how can I get the 3rd element?!


You're looking for the :eq() selector:

 $('.myClass:eq(2)')


Instead of $('.myClass:eq(2)') you can also use $('.myClass').eq(2) or, if you want a DOM element instead of a jQuery element, $('.myClass').get(2)

0

精彩评论

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