.size()    **DEPRECATED**S2C Home « DOM Element Methods « .size()

jQuery object element size.

Description

The .size() method is used to returns the number of elements in the jQuery object.

Use the .length property for the same results without the overhead of a function call.

This method was deprecated in jQuery 1.8.

Syntax


Signature Description
.size()Return number of elements in the jQuery object.

Parameters

None.

Return

A JavaScript Number object.

.size() Examplesgo to top of page Top

Retrieve DOM elements matched by the jQuery object.

In the example below we alert the number of table row / table data elements dependant upon button pressed.

Table For Testing The .size() Signature
Table Row 1, Table Data 1 Table Row 1, Table Data 2
Table Row 2, Table Data 1 Table Row 2, Table Data 2
Table Row 3, Table Data 1 Table Row 3, Table Data 2
Table Row 4, Table Data 1 Table Row 4, Table Data 2


$(function(){
  $('#btn4').on('click', function() {
    alert('The table has ' + $('.testtable tr').size() 
                           + ' table row elements.');
  });
  $('#btn5').on('click', function() {
    alert('The table has ' + $('.testtable td').size() 
                           + ' table data elements.');
  });
});

Press the button below to action the above code:

          

go to home page Homepage go to top of page Top