user2950593
user2950593

Reputation: 9647

How to get jquery object from $(.class)[0]

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

Answers (2)

user3755768
user3755768

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

Milind Anantwar
Milind Anantwar

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

Related Questions