Description: The number of elements in the jQuery object.
The number of elements currently matched. The .size() method will return the same value.
Example
Count the divs. Click to add more.Full source:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style>body { cursor:pointer; }
div { width:50px; height:30px; margin:5px; float:left; background:blue; }
span { color:red; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$(document.body).click(function () { $(document.body).append($("<div>"));
var n = $("div").length;
$("span").text("There are " + n + " divs." + "Click to add more.");}).click(); // trigger the click to start
});
</script>
</head>
<body>
<span></span>
<div></div>
</body>
</html>
Was this information helpful?

