locked
How to iterate in all table row with a specific class name RRS feed

  • Question

  • User264732274 posted

    suppose i have html table which has many rows. few TR has a specific class and i want to iterate in those TR which has a specific class. does the below code will solve my purpose?

    $("#tableMain tr.MyClass").each(function(index,value){
    
    });

    please guide. thanks

    Monday, January 18, 2016 5:47 PM

Answers

  • User264732274 posted

    i guess i got a solution

    <tr class="mycol">
        <td>Item 2
        </td>
    </tr>
    $("table#tblOne > tbody > tr[class='mycol']").each(function () {
        $(this).css("background-color", "red");
    });

    thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 18, 2016 5:51 PM
  • User61956409 posted

    Hi sudip_inn,

    suppose i have html table which has many rows. few TR has a specific class and i want to iterate in those TR which has a specific class. does the below code will solve my purpose?

    $("#tableMain tr.MyClass").each(function(index,value){
    
    });

    The above code should be working, the following sample code works fine on my side.

    $(function () {
        $("#tableMain tr.MyClass").each(function () {
            $(this).css("background-color", "red");
        })
    })
    
    <table id="tableMain">
        <thead>
            <tr>
                <td>Column1</td>
                <td>Column2</td>
            </tr>
        </thead>
        <tbody>
            <tr class="MyClass">
                <td>data1</td>
                <td>data1</td>
            </tr>
            <tr>
                <td>data2</td>
                <td>data2</td>
            </tr>
            <tr class="MyClass">
                <td>data3</td>
                <td>data3</td>
            </tr>
        </tbody>
    </table>
    

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 19, 2016 2:11 AM

All replies

  • User264732274 posted

    i guess i got a solution

    <tr class="mycol">
        <td>Item 2
        </td>
    </tr>
    $("table#tblOne > tbody > tr[class='mycol']").each(function () {
        $(this).css("background-color", "red");
    });

    thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 18, 2016 5:51 PM
  • User61956409 posted

    Hi sudip_inn,

    suppose i have html table which has many rows. few TR has a specific class and i want to iterate in those TR which has a specific class. does the below code will solve my purpose?

    $("#tableMain tr.MyClass").each(function(index,value){
    
    });

    The above code should be working, the following sample code works fine on my side.

    $(function () {
        $("#tableMain tr.MyClass").each(function () {
            $(this).css("background-color", "red");
        })
    })
    
    <table id="tableMain">
        <thead>
            <tr>
                <td>Column1</td>
                <td>Column2</td>
            </tr>
        </thead>
        <tbody>
            <tr class="MyClass">
                <td>data1</td>
                <td>data1</td>
            </tr>
            <tr>
                <td>data2</td>
                <td>data2</td>
            </tr>
            <tr class="MyClass">
                <td>data3</td>
                <td>data3</td>
            </tr>
        </tbody>
    </table>
    

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 19, 2016 2:11 AM