Both FM
Both FM

Reputation: 770

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?

Upvotes: 2

Views: 9069

Answers (3)

thecodeparadox
thecodeparadox

Reputation: 87073

$('#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 .

Upvotes: 6

Fluidbyte
Fluidbyte

Reputation: 5210

I would use .html()...

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

Also, keep in mind that an ID should not be/begin with a number.

Upvotes: 1

Sanket
Sanket

Reputation: 393

$(th_id).text() This will give the text value present with that particular dom element

Upvotes: 2

Related Questions