Pawan
Pawan

Reputation: 32331

How to get the date td value from the table

I am trying to get the date from the table

All the date in the table are same

I am trying to get the value '2015-12-21'

This is my table data

<table id="1dtopg" class="gaintable table table-striped">
   <thead>
      <tr>
         <th class="thheaders">Symbol</th>
         <th class="thheaders">Close</th>
         <th class="thheaders">Rs Chg</th>
         <th class="thheaders">% Chg</th>
         <th class="thheaders">As On</th>
      </tr>
   </thead>
   <tbody>
      <tr>
         <td>NILKAMAL</td>
         <td>1243.30</td>
         <td class="greenclass">172.45</td>
         <td class="greenclass">13.87</td>
         <td class="">2015-12-21</td>
      </tr>
      <tr>
         <td>LAXMIMACH</td>
         <td>3648.90</td>
         <td class="greenclass">148.95</td>
         <td class="greenclass">4.08</td>
         <td class="">2015-12-21</td>
      </tr>
      <tr>
         <td>TTKHLTCARE</td>
         <td>1076.30</td>
         <td class="greenclass">116.65</td>
         <td class="greenclass">10.84</td>
         <td class="">2015-12-21</td>
      </tr>
      <tr>
         <td>MONTECARLO</td>
         <td>536.45</td>
         <td class="greenclass">78.55</td>
         <td class="greenclass">14.64</td>
         <td class="">2015-12-21</td>
      </tr>
      <tr>
         <td>TRENT</td>
         <td>1647.60</td>
         <td class="greenclass">74.80</td>
         <td class="greenclass">4.54</td>
         <td class="">2015-12-21</td>
      </tr>
      <tr>
         <td>BOSCHLTD</td>
         <td>18287.40</td>
         <td class="greenclass">71.85</td>
         <td class="greenclass">0.39</td>
         <td class="">2015-12-21</td>
      </tr>
      <tr>
         <td>WABCOINDIA</td>
         <td>6025.10</td>
         <td class="greenclass">58.90</td>
         <td class="greenclass">0.98</td>
         <td class="">2015-12-21</td>
      </tr>
      <tr>
         <td>BBL</td>
         <td>852.40</td>
         <td class="greenclass">58.65</td>
         <td class="greenclass">6.88</td>
         <td class="">2015-12-21</td>
      </tr>
      <tr>
         <td>BAJFINANCE</td>
         <td>5869.80</td>
         <td class="greenclass">56.00</td>
         <td class="greenclass">0.95</td>
         <td class="">2015-12-21</td>
      </tr>
      <tr>
         <td>HEROMOTOCO</td>
         <td>2697.95</td>
         <td class="greenclass">54.80</td>
         <td class="greenclass">2.03</td>
         <td class="">2015-12-21</td>
      </tr>
   </tbody>
</table>

I have tried as

var date = $('#1dtopg').find('tbody tr td:eq(5)').html();

alert(date);

But its giving me symbol value

This is my jsfiddle

https://jsfiddle.net/gr1L23us/27/

Upvotes: 0

Views: 1316

Answers (5)

Anil  Panwar
Anil Panwar

Reputation: 2622

This should work:

$('#1dtopg').find('td:last').html();

Upvotes: 0

Mohamed-Yousef
Mohamed-Yousef

Reputation: 24001

you can use :last selector

var date = $('#1dtopg').find('tbody tr td:last').html();

or .last()

var date = $('#1dtopg').find('tbody tr td').last().html();

or you can use :nth-child(starts from 1) instead of :eq(starts from 0)

var date = $('#1dtopg').find('tbody tr td:nth-child(5)').html();

Upvotes: 1

Hemal
Hemal

Reputation: 3760

You can use :last operator of jQuery.

var date = $('#1dtopg').find('tbody tr td:last').html();
alert(date);

Upvotes: 0

void
void

Reputation: 36703

In eq instead of 5 use 4, in eq the base index of 0

Several ways:

Using :eq

$('#1dtopg').find('tbody tr td:eq(4)').html();

or using .eq

$('#1dtopg').find('tbody tr td').eq(4).html();

or using :last

$('#1dtopg').find('tbody tr td:last').html();

or using .last

$('#1dtopg').find('tbody tr td').last().html();

Upvotes: 0

Milind Anantwar
Milind Anantwar

Reputation: 82241

as per doc. eq selector has 0 based index:

index: Zero-based index of the element to match.

Thus it should be 4 instead of 5:

var date = $('#1dtopg').find('tbody tr td:eq(4)').html();

Upvotes: 1

Related Questions