JQuery .size() - Count the divs. Click to add more.
by aaronk85
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<span></span>
<div></div>
</body>
</html>
CSS
body { cursor:pointer; min-height: 100px; }
div { width:50px; height:30px; margin:5px;
float:left; background:blue; }
span { color:red; }
JavaScript
$(document.body)
.click(function() {
$(this).append( $("<div>") );
var n = $("div").size();
$("span").text("There are " + n + " divs. Click to add more.");
})
// trigger the click to start
.click();