html - how to get th's value from td in jquery? -


my table design follows :

  <table>       <thead>          <tr><th class='fc-id1 ui-widget-header'>09:00</th></tr>          <tr><th class='fc-id2 ui-widget-header'>09:30</th></tr>          <tr><th class='fc-id3 ui-widget-header'>10:00</th></tr>       </thead>       <tbody>           <tr id='res1'><td class='fc-id4 ui-widget-content fc-resource1 '><div class=day-content'></div></td></tr>           <tr id='res2'><td class='fc-id5 ui-widget-content fc-resource2 '><div class=day-content'></div></td></tr>           <tr id='res3'><td class='fc-id6 ui-widget-content fc-resource3 '><div class=day-content'></div></td></tr>       </tbody>   </table> 

now on page load want compare th's value current time. have unique resourceid compare tr id , td class.

i trying code. not working. giving null value.

  var td = $('.fc-resource'+ id); // id unique id coming ajax.   var th = td.closest('tbody').prev('thead').find('> tr > th:eq(' + td.index() + ')').html();   alert(th); 

can me please ?

just slight alteration code , should work:

var td = $('.fc-resource'+ id); // id unique id coming ajax. var th = td.closest('tbody').prev('thead').find('> tr > th:eq(' + td.closest('tr').index() + ')').html(); alert(th); 

please note .closest('tr') before .index()

here http://jsfiddle.net/rdzfu/ can see works html code provided.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -