I was wondering if the people over at jQuery implemented an alternative method to .get()
, as in one that returns a jQuery object instead of a DOM node.
This way, I don't have to
.get()
method with an additional $()
call and I especially don't want to do #2 because I will pretty much be reinventing the wheel, when a functionality already exists.
you can use .eq(index), which returns a jquery instance. For example
var mycoll = $("div.myDivs")
var firstElementOfCollection = mycoll.eq(0);
or as ThiefMaster pointed out in his comment below, these will work as well (and are potentially nicer depending what you are doing :))
$("div.myDivs:eq(0)");
$("div.myDivs:first");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.