jQuery - Get element from array as jQuery element?

吃可爱长大的小学妹 提交于 2019-11-28 22:39:22

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!