简体   繁体   中英

target each cell in a table

I have a table and each row represents a different math percentage grouping and each cell needs to show the high end and low end for each math equation. I need to iterate through the table rows then loop through the cells. And preform diffent math in each cell. ie: row[0] cell[1] = 1+2 , row[0] cell[2] = 2+4 ... I have attached an image of my table [table][1] .

<table class="table table-condensed table-bordered">
    <thead>
    <tr>
        <th class="noColor"></th>
        <th class="noColor">Low End</th>
        <th class="noColor">High End</th>
    </tr>
    </thead>
    <tbody id="tbody">
    <tr>
        <td>31%-40%</td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td>41%-45%</td>
        <td>-</td>
        <td>-</td>
    </tr>
    <!-- .. and so on .. -->
    </tbody>
</table>

Here is my For Loop:

 var tableRows = $('#tbody').find("tr");
    for(var i = 0; i < tableRows.length; i++) {
        var tableCell = tableRows.find("td");
        for(var j = 0; j < tableCell.length; j++) {
            [here is where Im confused]
        }
    }

I need to skip over the first cell in each row and preform a completely different math equation in cell 2 and 3 for each row and each row has a different math.

First row - cell 2 = total * 31% | cell 3 = total * 40%

Second row - cell 2 = total * 41% | cell 3 = total * 45%

and so on...

Thank you for you time and sorry for my rookieness

Hey I need more information to help you out further but here is how you can select the inside of the element. Tell me what you need done from here step by step in a very specific and clear way and I'll do my best.

 var tableRows = $('#tbody').find("tr");
    for(var i = 0; i < tableRows.length; i++) {
        var tableCell = tableRows[i].childNodes;
        for(var j = 0; j < tableCell.length; j++) {
            var currentRow = tableRows[i];
            var currentCell = tableCell[j].innerHTML;

            console.log(currentCell)

        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM