A repository of over 1000 quality jQuery plugins

jQuery .size()

Learn all about the jQuery function .size().

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.

Given a simple unordered list on the page:

1
2
3
4
<ul>
<li>foo</li>
<li>bar</li>
</ul>

Both .size() and .length identify the number of items:

1
2
alert( "Size: " + $( "li" ).size() );
alert( "Size: " + $( "li" ).length );

This results in two alerts:

Size: 2

Size: 2