javascript - getting value of my td cells by id in jQuery -


i have following html can see when inspecting element on google chrome.

<table id="table_id">     <tr role="row" class="odd">         <td id="aptdate0" class="sorting_1">2015-03-08</td>         <td id="aptdateend0" style="display:none;">2015-03-08</td>         <td id="start0">10:30:00</td>         <td id="end0">11:30:00</td>         <td id="duration0">01:00:00</td>         <td>john doe</td>         <td>jane doe<td>         <td id="status0">n/a</td>     </tr>     <tr role="row" class="odd">         <td id="aptdate1" class="sorting_1">2015-03-08</td>         <td id="aptdateend1" style="display:none;">2015-03-08</td>         <td id="start1">10:30:00</td>         <td id="end1">11:30:00</td>         <td id="duration1">01:00:00</td>         <td>john doe</td>         <td>jane doe<td>         <td id="status1">n/a</td>     </tr> ... , on </table> 

i using document.getelementbyid('id').innerhtml have call function inside $(document).ready(function() need use jquery values.

i have following loop:

for (i=0; < 10; i++){      var aptdate = $('#table_id #aptdate'+i).textcontent;     //textcontent returns undefined     var aptdate = $('#table_id #aptdate'+i).text();     //.text() returns empty string     var aptdate = $('#table_id #aptdate'+i).val();     //.val() returns undefined     var aptdate = $('#table_id #aptdate'+i).html;     //.html retturns function (e){return x.access(this,function(e){var       n=this[0]||{},r=0,i=this.length;if(e===t)return 1===n.nodetype?n.innerhtml.replace(gt,""):t;if(!("string"!=typeof e||tt.test(e)||!x.support.htmlserialize&&mt.test(e)||!x.support.leadingwhitespace&&yt.test(e)||at[(bt.exec(e)||["",""])[1].tolowercase()])){e=e.replace(vt,"<$1></$2>");try{for(;i>r;r++)n=this[r]||{},1===n.nodetype&&(x.cleandata(ft(n,!1)),n.innerhtml=e);n=0}catch(o){}}n&&this.empty().append(e)},null,e,arguments.length)}     console.log(aptdate);  } 

my datatable initialisation follows:

 $('#table_id').datatable({                 bprocessing: true,                 bserverside: true,                 "sajaxsource": "script.php",                 "rowcallback": function( row, data, index ) {                      if ( data[9] == "0" ) {                         $('td:eq(9)', row).html('not scanned');                         $('td:eq(9)', row).css("color", "red");                     }                     else if (data[9] !== data[12]){                         $('td:eq(9)', row).html('incorrect qr scanned');                         $('td:eq(9)', row).css("color", "red");                     }                     else{                         $('td:eq(9)', row).html('scanned');                     }                     $('td:eq(1)', row).css("display", "none");                     $('td:eq(12)', row).css("display", "none");                     $('td:eq(13)', row).css("display", "none");                      $('td:eq(0)', row).attr("id", "aptdate"+index);                     $('td:eq(1)', row).attr("id", "aptdateend"+index);                     $('td:eq(2)', row).attr("id", "start"+index);                     $('td:eq(3)', row).attr("id", "end"+index);                     $('td:eq(4)', row).attr("id", "duration"+index);                     $('td:eq(7)', row).attr("id", "status"+index);                     $('td:eq(8)', row).attr("id", "hasinternet"+index);                     $('td:eq(9)', row).attr("id", "qrscanned"+index);                     $('td:eq(12)', row).attr("id", "suid");                     $('td:eq(13)', row).attr("display", "aptid");                     //update();                   } }); 

how can innerhtml of td cells. can see have values on table on screen.

edit neglected mention i'm using datatables. has why these solutions not working me?

use .text() or .html(), .val() intended value="" attributes. can use native javascript property 'textcontent'.

http://jsfiddle.net/8f0oac6o/2/

for (i=0; < 2; i++){     var aptdate = $('#table_id #aptdate'+i).text();     console.log(aptdate);     var aptdate = $('#table_id #aptdate'+i).html();     console.log(aptdate);      var aptdate = document.getelementbyid ( "aptdate"+i ).textcontent;      console.log(aptdate);  } 

Popular posts from this blog