Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get tfoot th value by ID using jquery

Look at the following:

<table border="0" id="npoGridView">
            <thead>
                <tr>
                    <th>Quantity Order</th>
                    <th>Cost P.U</th>
                    <th>Total</th>
                </tr>
            </thead>
            <tbody>
                   //TD .......      
            </tbody>
               <tfoot>
                  <tr>
                    <th>Quantity Order</th>
                    <th>Cost P.U</th>
                    <th id="15">Total</th>
                  </tr>
              </tfoot>
        </table>

I have given id to th in tfoot (i.e. id="15"), Now I want to get th value using jquery.

How to get the specific th value form footer using jquery?

like image 396
Both FM Avatar asked Mar 15 '26 16:03

Both FM


1 Answers

$('#npoGridView tfoot').each(function() {
  console.log($('th', this).text());
});

To get the value of any specific th like <th id="15">Total</th>;

$('tfoot th#15').text();

you can get the value of th like following:

$('tfoot th:eq(0)').text(); // output: Quantity Order

$('tfoot th:eq(1)').text(); // output: Cost P.U

$('tfoot th:eq(2)').text(); // output: Total

You could use .text() or .html() as you need.

To update value of th then use:

$('tfoot th#15').html($grandTotal);

or

$('tfoot th#15').text($grandTotal);

NOTE Don't use only numeric value as id .

like image 75
thecodeparadox Avatar answered Mar 17 '26 04:03

thecodeparadox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!