Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8978759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:41:19+00:00 2026-06-15T19:41:19+00:00

i’m trying to write some dynamic code and i can’t be sure the element

  • 0

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:

   <something class='EitherMe'/>

   <table>
     <thead class = 'EitherMe'></thead>
     <tbody>
       <tr class = 'selectAfterThis'><td></td></tr>
        .
        .
        .
     </tbody>
     <tfoot class ='EitherMe'>
       <tr></tr>
       <tr class='OrMe'></tr>
     </tfoot>
   </table>

   <something class='OrMe'/>

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’

nextAll() doesn’t work. since it only gets the siblings.
is there any way to do this?

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.

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

update 3: here’s a mini plugin i wrote from wirey’s answer. hope it helps anyone else who has a problem like me: http://jsfiddle.net/jTLt2/4/ . 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.

please let me know if you test it. i want to know if it works 100%

here’s the code :

(function($){
    $.fn.nextInView = function(selector)
    {
        var ret = this.nextAll(selector);      
        for(var i = 0;this.parents().eq(i).find('body').length < 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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:41:20+00:00Added an answer on June 15, 2026 at 7:41 pm

    You need to separately add them into a collection.. then get the first out of the collection to find the closest one

    // get siblings first - they will always be before parents
    var ele = $('.selectAfterThis').nextAll('.OrMe');
    // get parent siblings after current parent - they will be before their children
    ele = ele.add($('.selectAfterThis').parent().nextAll('.OrMe'));
    // get descendants that match of parent slibings
    ele = ele.add($('.OrMe',$('.selectAfterThis').parent().nextAll()));
    // now get first in collection
    ele.first();​
    

    http://jsfiddle.net/fRq4z/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm trying to select an H1 element which is the second-child in its group
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.