Return the number of elements in the jQuery object.

.size()🡢 Integer

Note: This method has been removed in jQuery 3.0. 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:


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

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

This results in two alerts:

Size: 2

Size: 2

Count the divs.

  .click(function () {
    var n = $("div").size();
    $("span").text("There are " + n + " divs. Click to add more.");

  // Trigger the click to start

Looking for a Web Developer?


Hi! I'm Basti, author of this site. If you are looking for a web developer with 15+ years of experience, holla at me!

Be it the good 'ol jQuery, vanilla JS or modern frameworks like Vue and Svelte, front- or backend, I can help you.

Just write me at jobs@jqapi.com :)