How do I find closest element with jQuery
<p>I have the following HTML code:</p>

<pre><code>&lt;td&gt;
  &lt;input type="text" size="40" value="" name="related_image" id="related_image"&gt;  
  &lt;input type="button" class="button addImage" value="Get image url"&gt;
&lt;/td&gt;
&lt;td&gt;
  &lt;input type="text" size="40" value="" name="alternative_image" id="alternative_image"&gt;  
  &lt;input type="button" class="button addImage" value="Get image url"&gt;
&lt;/td&gt;
</code></pre>

<p>I need to figure out which button I click, then add some text to the nearest input text field.<br>
E.g. if I click the button in the first <code>&lt;td&gt;</code>, then I need to input some text into <code>related_image</code> text field.</p>

<p>I've tried with the followin jQuery, but it's not working:</p>

<pre><code>jQuery('.addImage').click(function() {
  var tmp = jQuery(this).closest("input[type=text]").attr('name');
  alert(tmp);
});
</code></pre>

<p>(I'm just retrieving the inputs name for testing.)</p>

<p>I think I might have to use <code>find</code> and / or <code>siblings</code>. But I'm not quite sure how.</p>

<p>Any help appreciated.</p>

<p><strong>EDIT</strong></p>

<p>I just managed to use this code<br>
<code>addImageEvent = jQuery(this).prevAll("input[type=text]:first")</code></p>

<p>Is using <code>prevAll</code> a bad choice?</p>
