.size()
** REMOVED **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 and removed in 3.0.
Syntax
Signature | Description |
---|---|
.size() | Return number of elements in the jQuery object. |
Parameters
None.
Return
A JavaScript Number
object.
.size()
ExamplesTop
Retrieve DOM elements matched by the jQuery object.
The example below no longer works from jQuery 3.0 onwards and is just shown as an example for people using earlier versions.
In the example below we alert the number of table row / table data elements dependant upon button pressed.
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.');
});
});