{"name":"size","type":"method","title":".size()","deprecated":"1.8","removed":null,"desc":"Return the number of elements in the jQuery object.","categories":["miscellaneous/dom-element-methods","version/1.0","deprecated/deprecated-1.8"],"entries":[{"return":"Integer","signatures":{"added":"1.0"},"examples":{"desc":"Count the divs. Click to add more.","code":"\n$( document.body )\n .click(function() {\n $( this ).append( $( \"
\" ) );\n var n = $( \"div\" ).size();\n $( \"span\" ).text( \"There are \" + n + \" divs. Click to add more.\" );\n })\n\n // Trigger the click to start\n .click();\n","css":"\n body {\n cursor: pointer;\n min-height: 100px;\n }\n div {\n width: 50px;\n height: 30px;\n margin: 5px;\n float: left;\n background: blue;\n }\n span {\n color: red;\n }\n","html":"\n\n
\n"},"longdesc":"\n

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

\n\n

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.

\n

Given a simple unordered list on the page:

\n
\n<ul>\n  <li>foo</li>\n  <li>bar</li>\n</ul>\n    
\n

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

\n
\nalert( \"Size: \" + $( \"li\" ).size() );\nalert( \"Size: \" + $( \"li\" ).length );\n    
\n

This results in two alerts:

\n

\n Size: 2\n

\n

\n Size: 2\n

\n "}]}