title: jQuery Get Input Name Array Key Value from Neighbouring TD
body: <p>Hard one to explain in the title, but a bit of code says it all:</p>
  <pre><code>&lt;tr class=&quot;&quot;&gt;
    &lt;td&gt;
      &lt;input value=&quot;9&quot; name=&quot;set[122][order]&quot;&gt;&lt;/input&gt;
      &lt;input class=&quot;set-id&quot; type=&quot;hidden&quot; value=&quot;1&quot; name=&quot;set[122][ex_id]&quot;&gt;&lt;/input&gt;
    &lt;/td&gt;
    &lt;td&gt;
      &lt;input value=&quot;0.00&quot; name=&quot;set[122][weight]&quot;&gt;&lt;/input&gt;
    &lt;/td&gt;
    &lt;td&gt; … &lt;/td&gt;
    &lt;td&gt;
      &lt;img class=&quot;deleteRowButton&quot; border=&quot;0&quot; title=&quot;Toggle Delete Set&quot; alt=&quot;Delete Set&quot; src=&quot;mysite/images/icons/png/delete-3x.png&quot;&gt;&lt;/img&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  <p>I have a bit of jQuery code that is activated when the img (deleteRowButton) is clicked:</p>
  <pre><code>$('.deleteRowButton').click (function() {
  
    $(this).parents(&quot;tr&quot;).toggleClass( &quot;deleteSet&quot; );
    var id = $('.set-id', $(this).closest('td')).val(); // this bit not working
  
    $('.editWoForm').append('&lt;input type=&quot;hidden&quot; name=&quot;deleteSet[]&quot; value=&quot;' + id + '&quot; /&gt;');
  });
  </code></pre>
  <p>The deleteRowButton code basically just inserts a hidden input tag at the bottom of my form, so i have the ability to process these to remove entries from db.</p>
  <p>BUT, what I need to do is grab the value from <code>set[]</code>, so in this example <code>122</code>. It can come from any of the inputs, as the whole <code>tr</code> is related to one entry. <code>122</code> is the db id, so that's what I need to grab.</p>
  <p>So ideally, when the user clicks on the deleteRowButton, it generates and inserts:</p>
  <pre><code>&lt;input type=&quot;hidden&quot; name=&quot;deleteSet[]&quot; value=&quot;122&quot; /&gt;
  </code></pre>
  <p>Thanks in advance!</p>
  <hr />
  <h2>Solution</h2>
  <p>Thanks to @ArunPJohny for the assistance.</p>
  <pre><code>$('.deleteRowButton').click (function() {
    var $tr = $(this).parents(&quot;tr&quot;).toggleClass( &quot;deleteSet&quot; );
    var id = $tr.find('.set-id').attr('name').match(/\d+/)[0];
  
    if($tr.hasClass( &quot;deleteSet&quot; )){
      $('.editWoForm').append('&lt;input type=&quot;hidden&quot; name=&quot;deleteSet[]&quot; value=&quot;' + id + '&quot; /&gt;');
    }
    else{
      $('input[name=&quot;deleteSet[]&quot;][value=&quot;' + id + '&quot;]').remove();
    }
  });
  </code></pre>
  <p>This will get the id, append a hidden input field with said id as the value, then if the button is pressed again (to toggle the delete state) the hidden input field is removed.</p>