title: Select closest element of certain type - JQuery
body: <p>I want to select an element with some selector, and the select the closest <code>&lt;p&gt;</code> element to it (note that the p is not nested with the former element). How would I do that? I tried <code>closest()</code>, but that only works if the element is nested.</p>
  
  <p>EDIT: a definition of closest:</p>
  
  <pre><code>&lt;a id="myelement"&gt;&lt;/a&gt;
  &lt;p id="1"&gt;&lt;/p&gt;
  &lt;p id="2"&gt;&lt;/p&gt;
  </code></pre>
  
  <p>In this case, <code>p#1</code> would be selected, assuming <code>#myelement</code> is the element in question.</p>