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 8667421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:57:34+00:00 2026-06-12T17:57:34+00:00

I feel like this question has been asked before but the answers seem pretty

  • 0

I feel like this question has been asked before but the answers seem pretty specific to each poster.

I’m looking for a way to identify a given element and find the next element that has a particular class. I don’t want to have to deal with parent() or children() since I’m parsing through a table and I don’t want it to stop at the end of a row or even the end of the table itself (there are two side-by-side).

Is there any way to just search the entire page for the next instance of an element?

BACKGROUND INFO:
http://jsfiddle.net/HKkAa/2/

I’m trying to iterate through the bottom table starting at the highlighted cell and applying the “highlight” class to each cell until I reach the end date. I have a way to calculate when I’ve reached the end date, I just need the magic method to select the next instance of a link.

  • 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-12T17:57:35+00:00Added an answer on June 12, 2026 at 5:57 pm

    Edit

    For anyone interested, I’ve plugin-ified this here: https://github.com/techfoobar/jquery-next-in-dom


    There is no built-in way of doing this in jQuery if you want it to be completely generic and able to satisfy all/any DOM structure. I once worked out a simple recursive function that does this. It goes like:

    function nextInDOM(_selector, _subject) {
        var next = getNext(_subject);
        while(next.length != 0) {
            var found = searchFor(_selector, next);
            if(found != null) return found;
            next = getNext(next);
        }
        return null;
    }
    function getNext(_subject) {
        if(_subject.next().length > 0) return _subject.next();
        return getNext(_subject.parent());
    }
    function searchFor(_selector, _subject) {
        if(_subject.is(_selector)) return _subject;
        else {
            var found = null;
            _subject.children().each(function() {
                found = searchFor(_selector, $(this));
                if(found != null) return false;
            });
            return found;
        }
        return null; // will/should never get here
    }
    

    And you can call it like:

    nextInDOM('selector-to-match', element-to-start-searching-from-but-not-inclusive);
    

    For ex:

    var nextInst = nextInDOM('.foo', $('#item'));
    

    will get you the first matching .foo after $('#item') regardless of the DOM structure

    Check the original answer here: https://stackoverflow.com/a/11560428/921204

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

Sidebar

Related Questions

Yes, this question has been asked before, but I don't feel there's been a
This question has been asked before, but I would like a little more detail
I feel like this question has to have been asked but for the life
I feel like this question has been asked many times, but the solution is
I know this question has been asked before, but I feel it wasn't asked
I feel like this one has been asked before, but I'm unable to find
I know that maybe this question has been asked before, but I can't seem
I know this question has been somewhat dealt with before, but I feel like
I feel like this has already been asked, but the answers for the questions
I feel like this must have been asked before, but I've looked at Knockout

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.