Find closest element in complete document
<p>I have indexed my document using Jquery <code>index</code> Given a certain index value, I would like to 'locate' the 'nearest' element with some <code>class</code>. This will not work for me:</p>

<pre><code>$(variableIndexNumber).closest('.class');
</code></pre>

<p>The reason is that sometimes the <code>.class</code> changes its position, meaning it could be anywhere in the document. Sometimes its a sibling, sometimes a parent, sometimes way up in document or in the bottom. So the usual selctors <code>next</code> <code>closest</code> <code>first</code> <code>nextAll</code> etc don't work for me (because of document tree) </p>

<p>What can I try to get the nearest <code>.class</code> relative to some other element (given by variable)? </p>
