The number of elements in the jQuery object.

.length()🡢 Integer

The number of elements currently matched. The .size() method will return the same value.

Count the divs. Click to add more.

body {
  cursor: pointer;
div {
  width: 50px;
  height: 30px;
  margin: 5px;
  float: left;
  background: green;
span {
  color: red;
  .click(function () {
    var n = $("div").length;
    $("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 :)