Ashok Chitroda
Ashok Chitroda

Reputation: 361

What is the difference between jquery.size() and jquery.length?

What is the difference between jquery.size() and jquery.length? like:

$('#test').size();
$('#test').length;

Upvotes: 0

Views: 2209

Answers (6)

Vinod VT
Vinod VT

Reputation: 7149

The .size() method returns number of element in the object. But it is preferred to use .length property which does the same thing but it does not have the overhead of a function call.

Ref : http://tonyfreed.com/blog/top_jquery_interview_question_2015

Upvotes: 1

Don D
Don D

Reputation: 754

Both length property and size() are same. But length property is preferred as a much effective way.

Refer https://api.jquery.com/size/

Upvotes: 0

Naqash Malik
Naqash Malik

Reputation: 1816

No, both are same. size() actually returns length. So use directly length to avoid extra method call.

Upvotes: 0

ADreNaLiNe-DJ
ADreNaLiNe-DJ

Reputation: 4919

It returns the same value. But size() is deprecated since jQuery 1.8

Upvotes: 0

connexo
connexo

Reputation: 56754

The .size() method is deprecated as of jQuery 1.8. Use the .length property instead.

The .size() method is functionally equivalent to the .length property; however, the .length property is preferred because it does not have the overhead of a function call.

http://api.jquery.com/size/

Upvotes: 2

Atul Pandya
Atul Pandya

Reputation: 333

jQuery .size() method returns number of element in the object. But it is not preferred to use the size() method as jQuery provide .length property and which does the same thing. But the .length property is preferred because it does not have the overhead of a function call.

Upvotes: 2

Related Questions