mardi 7 novembre 2017

Find first td, of every select checkbox

I have a table as follows:

<table id="testTable" class="mainTable">
    <thead>
        <tr>
            <th>Title</th>
            <th>
                Select All
                <input type="checkbox" id="select_all">
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Cell 1</td>
            <td><input type="checkbox" class="checkbox"></td>
        </tr>
        <tr>
            <td>Cell 2</td>
            <td><input type="checkbox" class="checkbox"></td>
        </tr>
        <tr>
            <td>Cell 3</td>
            <td><input type="checkbox" class="checkbox"></td>
        </tr>
        <tr>
            <td>Cell 4</td>
            <td><input type="checkbox" class="checkbox"></td>
        </tr>
    </tbody>
</table>

Currently, my JS code will get all first td elements from the table regardless of the checkbox, code is as follows:

$("#testTable tr").each(function() {
    firsttd += $(this).find("td:first").html() + "\n";
});

However, I need to modify this so that my JS code will only get the first td element of the checked checkbox row.




Aucun commentaire:

Enregistrer un commentaire