2

I have the following markup. How do I find the number of trs with the class abc in the table?

<html>
    <body>
        <table>
            <tr class='abc'>
                <td> i am from bd </td>
                <td> i am from bd </td>
                <td> i am from bd </td>
            </tr>
        </table>
    </body>
</html>
SUB0DH
  • 5,130
  • 4
  • 29
  • 46
Rehan Uddin
  • 23
  • 1
  • 4

4 Answers4

4

You can use .length to count of total elements as below

alert($("tr.abc").length);
console.log($("tr.abc").length)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <tr class='abc'>
    <td> i am from bd </td>
    <td> i am from bd </td>
    <td> i am from bd </td>
  </tr>
</table>
Curiousdev
  • 5,668
  • 3
  • 24
  • 38
2

You can use length function for this

alert($('tr.abc').length)
Super User
  • 9,448
  • 3
  • 31
  • 47
0

Use .length

 $(document).ready(function() {
        console.log($('tr.abc').length);
        )};


  
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
0

check this fiddle https://jsfiddle.net/ajeshkolakkadan/d41fL4e3/

$(function () {
   var rc = $('.mytable tr').length;
   alert(rc)
});