最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How to find total tr with a specific class using jquery? - Stack Overflow

matteradmin4PV0评论

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>

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>
Share Improve this question edited Mar 27, 2017 at 11:50 SUB0DH 5,2405 gold badges31 silver badges47 bronze badges asked Mar 27, 2017 at 11:33 Rehan UddinRehan Uddin 231 silver badge4 bronze badges 3
  • This is basic jQuery: $('table > tr.abc').length – W. van Kuipers Commented Mar 27, 2017 at 11:48
  • Possible duplicate of jQuery: count number of rows in a table – W. van Kuipers Commented Mar 27, 2017 at 11:49
  • thanks i got it dear – Rehan Uddin Commented Mar 27, 2017 at 11:50
Add a ment  | 

4 Answers 4

Reset to default 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./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>

You can use length function for this

alert($('tr.abc').length)

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

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

Use .length

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


  
Post a comment

comment list (0)

  1. No comments so far