title: Jquery closest function with class not alerting in javascript code become undefined value
body: <p>I have a code that waste my few hours. Here jquery closest with class not working in html table and not passing value. I use html, javascript, jquery and php here. Can anyone rewrite the code freshly.   </p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function () {
      $(".senddata").on("click", function () {
          var subans = 
   $(this).closest(".datadivision").find("input[name='subans']").val();
          var data = 'subans=' + subans;
          $.ajax({
              type: "POST",
              url: "test.php",
              data: data,
              cache: false,
              success: function (html) {
                  alert(html);
              }
          });
      });
      });
   &lt;/script&gt;
  
    &lt;table&gt;
    &lt;tr class="datadivision"&gt;
    &lt;input type="hidden" name="subans" value="A" &gt;
    &lt;td class= "senddata"&gt;       
    &lt;label&gt;&lt;input type="radio" name="subans" value="something"&gt; This is a 
    line&lt;/label&gt;     
    &lt;/td&gt; 
   &lt;/tr&gt;
   &lt;/table&gt;
  
   &lt;?php
    if (isset($_POST['subans'])) {
      $subans = $_POST['subans'];
     if (!empty($subans)) {
      echo $subans;
      }
     }
     ?&gt;
  </code></pre>