Getting data from a specific column in a HTML table when a checkbox in that row is checked using Javascript/JQuery
<p>I have a HTML table with 5 columns. The first column is a checkbox. I want to find the content of the 5th column (last column) when the checkbox in that row is checked.</p>

<p><strong>HTML :</strong></p>

<pre><code>    &lt;table&gt;
     &lt;tr&gt;
      &lt;th&gt;&lt;/th&gt;
      &lt;th&gt;A&lt;/tr&gt;
      &lt;th&gt;B&lt;/tr&gt;
      &lt;th&gt;C&lt;/tr&gt;
      &lt;th&gt;D&lt;/tr&gt;
     &lt;/tr&gt;
     &lt;tr&gt;
      &lt;td&gt;&lt;input type='checkbox' class="chk" /&gt;&lt;/td&gt;
      &lt;td&gt;data for A1&lt;/td&gt;
      &lt;td&gt;data for B1&lt;/td&gt;
      &lt;td&gt;data for C1&lt;/td&gt;
      &lt;td&gt;data for D1&lt;/td&gt;
     &lt;/tr&gt;
     &lt;tr&gt;
      &lt;td&gt;&lt;input type='checkbox' class="chk"/&gt;&lt;/td&gt;
      &lt;td&gt;data for A2&lt;/td&gt;
      &lt;td&gt;data for B2&lt;/td&gt;
      &lt;td&gt;data for C2&lt;/td&gt;
      &lt;td&gt;data for D2&lt;/td&gt;
     &lt;/tr&gt;
    &lt;/table&gt;
</code></pre>

<p>I am a beginner in javascript but have tried doing this.</p>

<p>**JS : **</p>

<pre><code>    $(document).ready(function(){
      if($('input.chk').is(':checked')){
         var y = $("td:nth-of-type(5)").html();
         alert(y);
         }
      });
</code></pre>

<p>This function returns only for the first row i.e when the checkbox is checked it shows "data for D1". But I want it for all the rows.</p>

<p>Thanks for your help. :)</p>