Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Last td of each line in html table

I know it's already been asked before, however I've tried previous solutions and they're not working for me.

I've got a HTML table as so which is being generated by AJAX:

<table cellspacing="1" cellpadding="7" summary="Procedure Tabulate: Table 1" frame="box" rules="groups" class="table table-bordered table-hover">
    <thead>
        <tr>
            <th scope="col" class="c m Header">&nbsp;</th>
            <th scope="col" class="c Header">reel</th>
            <th scope="col" class="c Header">budgete</th>
            <th scope="col" class="c Header">ecart</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <th scope="row" class="l t RowHeader">Fours</th>
            <td class="r b Data">15 341,10</td>
            <td class="r b Data">15 540,90</td>
            <td nowrap="" class="r b Data">  -1.29% </td>
        </tr>
        <tr>
            <th scope="row" class="l t RowHeader">Hifi</th>
            <td class="r b Data">10 578,60</td>
            <td class="r b Data"> 9 962,50</td>
            <td class="r b Data">   6.18% </td>
        </tr>
        <tr>
            <th scope="row" class="l t RowHeader">Magneto</th>
            <td class="r b Data">10 090,10</td>
            <td class="r b Data">10 495,60</td>
            <td nowrap="" class="r b Data">  -3.86% </td>
        </tr>
        <tr>
            <th scope="row" class="l t RowHeader">Total</th>
            <td class="r b Data">36 009,80</td>
            <td class="r b Data">35 999,00</td>
            <td class="r b Data">   1.04% </td>
        </tr>
    </tbody>
</table>

I don't have much control over the classes in the table as they are being created by another group of people using SAS (Statistical Analysis Software).

I would like to get the last td of each row in tbody.

For the moment I've got the following jQuery to do the job:

$( '#ajax-area table tbody tr td:last' ).addClass( 'result' );

This isn't adding the class to the td.

Does anyone have a solution?

like image 255
xonorageous Avatar asked Mar 12 '13 09:03

xonorageous


People also ask

How do you find the last tr in a table?

Approach 2: Use $('table tr:last') jQuery Selector to find the last element of the table. The 'table' in query looks for the table element then 'tr' is looking for all the rows in the table element and ':last' is looking for the last table row of the table.

What is TD and TH tags?

The TH and TD elements are used for table cells. TH is used for table header cells while TD is used for table data cells. This distinction gives user agents a means to render such cells distinctly, for instance by using a larger or heavier font for header cells. It is also needed when rendering to speech.

What are lines in TD?

A TD Lines trendline is drawn through two TD Points. A supply trendline is drawn between a TD Point high (Point “B”) and the most recent prior TD Point low (point “A”) that is strictly greater than point B. The line is then extended to the right of point B according to the rules below.


1 Answers

Try

$( 'table tbody tr td:last-child').addClass( 'result' );

Demo: Fiddle

like image 123
Arun P Johny Avatar answered Oct 25 '22 19:10

Arun P Johny