title: jQuery to find closest table under a div tag
body: <p>I am trying to find the table headers using jQuery. This is what I tried but I couldn't get it working.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(function() {
  
      var str = "FinalDate"; //change this based on col header 
  
      var today = new Date();
      //today = Date.parse(today)/1000;
  
  
          var a=0;
  
      var headers = $($(ctl00_MSO_ContentDiv).closest('table')+":first&gt; tbody&gt; tr:first th").get();
  
  
      $.each(headers, function(i,e){
          x = $(e).contents().find("a[title*='"+str+"']").length;
  alert("X :"+x);
  //x=3;
  
          a = x &gt; 0 &amp;&amp; i &gt; a ? i : a;
  alert("A :"+a);
  //a=3;
  
  
      });
      var dArray = $($(ctl00_MSO_ContentDiv).closest('table')+":first&gt; tbody&gt; tr:gt(0)").find("&gt;td:eq("+a+")").get()
  
    var dArray2 = $("table.ms-listviewtable:first&gt; tbody&gt; tr:gt(0)").find("&gt;td:eq(4)").get()
  
  $.each(dArray, function(i,e){
  alert("i "+i+" e "+e);
          var d1 = $(e).text();
  
             $.each(dArray2, function(i,e){
          $(e).text(today);
         });
      });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>What I am trying to achieve is read value in expected date and according set <code>FinalDate</code>. But I am unable to get the headers and than iterate through the same. Can anybody please help?</p>
  
  <p>The below image shows the results I achieved using hardcoding index values.</p>
  
  <p><img src="https://i.stack.imgur.com/8l9AT.jpg" alt="enter image description here"></p>