jQuery to check the row count of a table

To get the row count of the table, in jQuery, all you need to do is use any of the following approaches:

$(“#mytable tr”).length

$(“#mytable tr”).size() //But the size method calls the length property internally

One thing to be noted here is that the indexing is 1-based and not 0-based. For ex.:

<script src=”jquery-1.3.2.min.js” type=”text/javascript” language=”javascript”></script>
<script type=”text/javascript” language=”javascript”>
alert($(“#x tr”).length);

<table id=”x”>

Running the above html will give ‘8’ as the result and not 7.

  1. Chances are you can swap out quite even cash-wise.


  2. Bobbi Leder: Did you take any supplements or protein shakes?
    Girls’s Well being.


  3. I do not drop a comment, however after looking at through a few of the comments on this page
    jQuery to check the row count of a table | The Relentless FrontEnd – Aackose Lal’s Blog. I do have a few questions for you if it’s allright.
    Could it be simply me or does it look like a few of these comments appear like they
    are left by brain dead people? 😛 And, if
    you are writing at other online sites, I would like to follow you.
    Would you post a list of every one of your social sites like your Facebook page, twitter feed, or linkedin


  4. Sorry, it didn’t work either… must be something else 😦


  5. Hi,
    Using $(“#mytable tr”).length didn’t work, at least in my environment.. but it worked using

    $(“#mytable tr”).children.length

    It could be because of the version of jquery?


Feel free to leave a reply here...

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: