title: jQuery: Get ID Of Closest Text Input
body: <p>I have a text input field, next to this there is a button. When I click this button, I want alert() to show me the ID of the input field. This is my code</p>
  
  <pre><code>&lt;tr&gt;
     &lt;td&gt;Item &lt;?php echo $i; ?&gt;:&lt;/td&gt;
     &lt;td&gt;
         &lt;input type="text" name="course_include_1" class="regular-text" /&gt; &lt;input type="button" class="button" id="DeleteItem" value="Delete Item" /&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>And this is my jQuery code:</p>
  
  <pre><code>    $("#DeleteItem").live("click", function() {
          //$(this).parents("tr").remove();
          alert($(this).prev().attr("id"));
      });
  </code></pre>
  
  <p>Why is this not working?</p>
  
  <p><strong>Edit:</strong> I should add that the there is also a "Add" button which creates a new input field along with the delete button next to it. The code for this looks like this:</p>
  
  <pre><code>$("#AddItem").live("click", function() {
              Count++;
              $('&lt;tr&gt;&lt;td&gt;Item ' + Count + ':&lt;/td&gt;&lt;td&gt;&lt;input id="asdadad" name="course_include_' + Count + '" type="text" class="regular-text" /&gt; &lt;input type="button" class="button" id="DeleteItem" value="Delete Item" /&gt;&lt;/td&gt;&lt;/tr&gt;').appendTo(TableRow);
          });
  </code></pre>
  
  <p>The goal is to click on the delete button next to the newly created field and show its ID in an alert() box. And that's not working.</p>