getting all elements after a certain element, including their children
<p>i'm trying to write some dynamic code and i can't be sure the element i'm after is sibling or child of a sibling.
i just have a class and must search for the first element that has this class after my element.
example:</p>

<pre><code>   &lt;something class='EitherMe'/&gt;

   &lt;table&gt;
     &lt;thead class = 'EitherMe'&gt;&lt;/thead&gt;
     &lt;tbody&gt;
       &lt;tr class = 'selectAfterThis'&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
        .
        .
        .
     &lt;/tbody&gt;
     &lt;tfoot class ='EitherMe'&gt;
       &lt;tr&gt;&lt;/tr&gt;
       &lt;tr class='OrMe'&gt;&lt;/tr&gt;
     &lt;/tfoot&gt;
   &lt;/table&gt;

   &lt;something class='OrMe'/&gt;
</code></pre>

<p>i'll get 'EitherMe' or 'OrMe' depending on the user's need. and i need to select exactly the element with that class that comes after 'selectAfterThis'</p>

<p>nextAll() doesn't work. since it only gets the siblings.
is there any way to do this?</p>

<p>update: i put the thead in the above example.since most suggestion were going through the parent. and i don't really know if there is no element with class higher up.
i could limit my plugin by limiting the class's exact location but i want to avoid that if possible.</p>

<p>update2: simply put, i need the element with the specified class, that comes below 'selectAfterThis', whether its just below him, or far below him, or its parent-child relationship with 'selectAfterThis' doesn't matter</p>

<p>update 3: here's a mini plugin i wrote from wirey's answer. hope it helps anyone else who has a problem like me: <a href="http://jsfiddle.net/jTLt2/4/" rel="nofollow">http://jsfiddle.net/jTLt2/4/</a> . all credits go to wirey. i just did a few modifications to make it go deeper than just parent sibling and child of parents siblings.</p>

<p>please let me know if you test it. i want to know if it works 100%</p>

<p>here's the code :</p>

<pre><code>(function($){
    $.fn.nextInView = function(selector)
    {
        var ret = this.nextAll(selector);      
        for(var i = 0;this.parents().eq(i).find('body').length &lt; 1 ;i++){
            ret = ret.add(this.parents().eq(i).nextAll(selector));  
            ret = ret.add(this.parents().eq(i).nextAll().find(selector));
        }            
        return ret.first();
    }
})(jQuery)
</code></pre>
