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)
精彩评论