Monday, July 25, 2011

size() → Number

This returns the same number as the '<a href='Core/length'>length</a>' property of the jQuery object
Example:

Count the divs. Click to add more.
$(document.body).click(function () {
   $(document.body).append($("<div>")); 
  var n = $("div").size(); 
  $("span").text("There are " + n + " divs." + "Click to add more."); }).click(); // trigger the click to start

<span></span> <div></div>
body { cursor:pointer; } 
div { width:50px; height:30px; margin:5px; float:left; 
background:blue; } span { color:red; }

No comments:

Post a Comment