title: How to get table header value using jquery
body: <p>I am having problem with getting table header value using jquery function.
  I have timetable module.in that the view page contains table format like period_timing and weekdays.</p>
  
  <pre><code> days   09.00AM - 10.00AM   10.00Am-11.00AM  11.00AM-12.00PM  ........
  
   Mon         Assign             Assign           Assign
  
   Tues        Assign             Assign           Assign
  
   Wed         Assign             Assign           Assign
  
   ..
  </code></pre>
  
  <p>In this Table Days are stored in weekday model and period timings are in Period_timing model.When I click assign link it shows the modal window(popup window). which contains subject_id label.We can select subjects from drop down list. while saving subject in popup window.it send subject_id in params. But I need weekday_id and Period_timing_id also. so, I have tried jquery for getting table header value .Is it correct way for getting period_timing id and weekday_ids.</p>
  
  <p>And also I have included coding.</p>
  
  <p>In Controller</p>
  
  <pre><code>def timetable
       @timetable_entry =   TimetableEntry.new(params[:subject_id])
  
      if params[:course].present?
        @timetable = CoursePeriod.where(:course_id =&gt; params[:course])
  
        @view = @timetable.first.period_timings
  
        @week = WeekdayEntry.where(:status=&gt; true).pluck(:weekday_id)
        @first_day  = Weekday.find(@week[0]).day
        @second_day = Weekday.find(@week[1]).day
        @third_day  = Weekday.find(@week[2]).day
        @fourth_day = Weekday.find(@week[3]).day
        @fifth_day  = Weekday.find(@week[4]).day
        render :partial =&gt; "table"
  
    end
  end
  
  
  
   def subject_entry  
    #raise params.inspect      
      TimetableEntry.create(:subject_id =&gt; params[:timetable_entry][:subject_id])
    end
  </code></pre>
  
  <p>In View _table.html.erb</p>
  
  <pre><code>&lt;table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered"&gt;
      &lt;thead&gt;
              &lt;th&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Days &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/th&gt;
              &lt;% @view.each do |i| %&gt; 
              &lt;th&gt;&lt;%=i.start_time.strftime("%I:%M %p") %&gt;--&lt;%= i.end_time.strftime("%I:%M %p") %&gt;&lt;/th&gt;
                 &lt;% end %&gt;         
      &lt;/thead&gt;
           &lt;tbody&gt;
                  &lt;tr&gt;
                    &lt;td&gt;&lt;%= @first_day %&gt;&lt;/td&gt;
                     &lt;% (1..@view.count).each do |j|%&gt;
  
                     &lt;td&gt;&lt;%= link_to "Assign","#myModal", :class =&gt; "assign", "data-toggle" =&gt; "modal" %&gt;
                  &lt;div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt;
                    &lt;div class="modal-header"&gt;
                      &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;×&lt;/button&gt;
                       &lt;h3 id="myModalLabel"&gt;Timetable Entries&lt;/h3&gt;
                    &lt;/div&gt;
  
                    &lt;div class="modal-body"&gt;
                      &lt;%= form_for (@timetable_entry),url: subject_entry_path, method: :get do |f| %&gt;
                      &lt;%= f.label :subject_id %&gt;
  
                      &lt;%= f.select :subject_id, options_from_collection_for_select(Subject.all,"id", "name"),class: "display_mark",:prompt =&gt; "--Select--" %&gt;
                      &lt;%= f.submit "Create" %&gt;
                      &lt;% end %&gt;
                    &lt;/div&gt;
  
                    &lt;div class="modal-footer"&gt;
                      &lt;button class="btn" data-dismiss="modal" aria-hidden="true"&gt;Close&lt;/button&gt;
                      &lt;button class="btn btn-primary"&gt;Save changes&lt;/button&gt;
                    &lt;/div&gt;
  
                  &lt;/div&gt;
  
                 &lt;/td&gt;
                    &lt;% end %&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                     &lt;td&gt;&lt;%= @second_day %&gt;&lt;/td&gt;
                       &lt;% (1..@view.count).each do |j|%&gt;
                       &lt;td&gt;&lt;%= link_to "Assign", "#myModal", :class =&gt; "", "data-toggle" =&gt; "modal" %&gt;&lt;/td&gt;
                    &lt;% end %&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                     &lt;td&gt;&lt;%= @third_day %&gt;&lt;/td&gt;
                     &lt;% (1..@view.count).each do |j|%&gt;
                     &lt;td&gt;&lt;%= link_to "Assign", "#myModal", :class =&gt; "", "data-toggle" =&gt; "modal" %&gt;&lt;/td&gt;
                    &lt;% end %&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                     &lt;td&gt;&lt;%= @fourth_day %&gt;&lt;/td&gt;
                     &lt;% (1..@view.count).each do |j|%&gt;
                     &lt;td&gt;&lt;%= link_to "Assign", "#myModal", :class =&gt; "", "data-toggle" =&gt; "modal" %&gt;&lt;/td&gt;
                    &lt;% end %&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                     &lt;td&gt;&lt;%= @fifth_day %&gt;&lt;/td&gt;
                     &lt;% (1..@view.count).each do |j|%&gt;
                     &lt;td&gt;&lt;%= link_to "Assign", "#myModal", :class =&gt; "", "data-toggle" =&gt; "modal" %&gt;&lt;/td&gt;
                    &lt;% end %&gt;
                  &lt;/tr&gt;
          &lt;/tbody&gt;      
  
  &lt;/table&gt;
  </code></pre>
  
  <p>And I tried jquery for getting table header value. But which shows Days text.</p>
  
  <pre><code>$("body").on('click', '.assign', function(){
      var col = $(this).prevAll().length;
    var headerObj = $(this).parents('table').find('th').eq(col);
     // A quick test!
    alert("My cell header is called: " + headerObj.text());
  });
  </code></pre>
  
  <p>Please Share your ideas</p>