.length
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.
JS
<span></span>
<div></div>
CSS
body {
cursor: pointer;
}
div {
width: 50px;
height: 30px;
margin: 5px;
float: left;
background: green;
}
span {
color: red;
}
HTML
$(document.body)
.click(function () {
$(document.body).append($("<div>"));
var n = $("div").length;
$("span").text("There are " + n + " divs." + "Click to add more.");
})
// Trigger the click to start
.trigger("click");
DEMO