Reputation: 9647
So the question is simple How to reduce this code and get jquery object of needed element? Or is it the best way?
$($('.myclass')[0])
Upvotes: 1
Views: 589
Reputation: 67
I have this solution
yes, using selector like .myclass:first is the simple way but according jsperf.com
$('.myclass').first();
have more performance, fast and recommended
Upvotes: 2
Reputation: 82251
if you want to get jquery object of first element then use :first
or :eq(0)
selectors:
$('.myclass:first');
or
$('.myclass:eq(0)');
Upvotes: 4