Use the eq()
method:
$(".myClass").eq(0)
This returns a jQuery object, whereas .get()
returns a DOM element.
.eq()
lets you specify the index, but if you just want the first you can use .first()
, or if you just want the last you can use (surprise!) .last()
.
"I get an array of elements."
No you don't, you get a jQuery object which is an array-like object, not an actual array.
If you plan to use jQuery much I suggest spending half an hour browsing through the list of all methods.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…