javascript - Set the last td value on basis of his data using jquery -
i working on 1 table created using datatables. want set last td value using jquery. tried different codes no luck this.
<script type="text/javascript"> $(document).ready(function() { $('#productstable tr').each(function() { alert($(this).closest('tr').children('td.two').text()); // alert($(this).closest('tr').find('td:eq(11)').text()); }); }); </script>
i didn't proper value of last td. table html is:
<table class="display table table-bordered table-striped datatable" id="productstable" aria-describedby="productstable_info"> <thead> <tr role="row"> <th class="sorting_desc" tabindex="0" rowspan="1" colspan="1" aria-label="date: activate sort column ascending" style="width: 45.777777671814px;">date</th> <th class="sorting" tabindex="0" rowspan="1" colspan="1" aria-label="auction: activate sort column ascending" style="width: 75.777777671814px;">auction</th> <th class="sorting" tabindex="0" rowspan="1" colspan="1" aria-label="bid no: activate sort column ascending" style="width: 62.777777671814px;">bid no</th> <th class="sorting" tabindex="0" rowspan="1" colspan="1" aria-label="name: activate sort column ascending" style="width: 55.777777671814px;">name</th> <th class="sorting" tabindex="0" rowspan="1" colspan="1" aria-label="chassis no: activate sort column ascending" style="width: 107.777777671814px;">chassis no</th> <th class="sorting" tabindex="0" rowspan="1" colspan="1" aria-label="year: activate sort column ascending" style="width: 46.777777671814px;">year</th> <th class="sorting" tabindex="0" rowspan="1" colspan="1" aria-label="color: activate sort column ascending" style="width: 53.777777671814px;">color</th> <th class="sorting" tabindex="0" rowspan="1" colspan="1" aria-label="mileage: activate sort column ascending" style="width: 75.777777671814px;">mileage</th> <th class="sorting" tabindex="0" rowspan="1" colspan="1" aria-label="score: activate sort column ascending" style="width: 58.777777671814px;">score</th> <th class="sorting" tabindex="0" rowspan="1" colspan="1" aria-label="bid: activate sort column ascending" style="width: 35.777777671814px;">bid</th> <th class="sorting" tabindex="0" rowspan="1" colspan="1" aria-label="end price: activate sort column ascending" style="width: 95.777777671814px;">end price</th> <th class="sorting_disabled" tabindex="0" rowspan="1" colspan="1" aria-label="result" style="width: 63.777777671814px;">result</th> </tr> </thead> <tbody role="alert" aria-live="polite" aria-relevant="all"> <tr class="odd"> <td class=" sorting_1">2015-05-08</td> <td class="">saa sapporo</td> <td class="">3005</td> <td class="">fit shuttle</td> <td class=""></td> <td class="">2012</td> <td class="">white</td> <td class="">23</td> <td class="">4.5</td> <td class="">0</td> <td class="">0</td> <td class="">1</td> </tr> <tr class="even"> <td class=" sorting_1">2015-05-08</td> <td class="">saa sapporo</td> <td class="">55097</td> <td class="">pixis epoch</td> <td class=""></td> <td class="">2012</td> <td class="">.....</td> <td class="">8</td> <td class="">4.5</td> <td class="">0</td> <td class="">0</td> <td class="">0</td> </tr> </tbody> </table>
i trying set result values if 1
winner , 2
losre etc., issue not getting value of last td. doing wrong.
you need use :last
selector along td elements object:
$('#productstable tr:has(td)').each(function() { alert($(this).find('td:last').text()); });
this alert text of each last td element in trs.
Comments
Post a Comment