当前位置: 动力学知识库 > 问答 > 编程问答 >

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;

网友答案:

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.

网友答案:

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/

网友答案:

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

网友答案:

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

网友答案:

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

网友答案:

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

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: