jQuery size() method vs length attribute

Is there any difference between $(".selector").size() and $(".selector").length ?


No. size() returns length. By using length you only avoid one extra method call.


Length returns the same thing and is slightly faster according to the jQuery documentation.

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


They will both give you the same result but .length is slightly faster.

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

The .length property is a slightly faster way to get this information.


Length is much faster.

See the tutorial size vs. length.


.size() is a Method call, which returns the length property. So you either call the method to return the property, or you retrieve the property directly.

The method (.size()) is probably the one you should be using, as it was most likely implemented to abstract away from the possibility of the length property being changed.