tadam logo
Did you find an error in the text?
Select this with mouse and press
Ctrl + Enter
Xhtml.co.il Check Spelling
Orphus system

length

Returns: Number
version added: 1.0
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.
$(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
The output of the code above will be:
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?
   

Comments