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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:24:43+00:00 2026-05-22T02:24:43+00:00

<li> <select id=foo></select> </li> <li> <select id=bar></select> </li> <li> <select id=baz></select> </li> var select_after

  • 0
<li>
  <select id="foo"></select>
</li>
<li>
  <select id="bar"></select>
</li>
<li>
  <select id="baz"></select>
</li>

var select_after = function(src){
   //How get all select elements after the one specified as argument ?
}

How write this method ?

select_after($("#foo")) 

should return #bar and #baz elements in array

select_after($("#bar"))

should return #baz element in array

select_after($("#baz")) 

should return empty array

How should I write this method ?

  • 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-05-22T02:24:44+00:00Added an answer on May 22, 2026 at 2:24 am

    For a simple single-liner you could use the following chain:

    $("#foo").parent().nextAll().children("select");
    

    The code above will first select the parent, which is the li element, then select all of the siblings that comes after it, and finally return the select elements within. As seen in this fiddle.

    However, this method is both bulky and slow since you are walking the DOM. Another method that I rather use because it is way faster when working with a larger set of elements,

    Preselection of all select elements, then create an object with references of the id to the index by looping them. Now you can just splice the jQuery object to get the elements that comes after (or before).

    // Preselect select elements
    var selects = $("ul > li > select"),
        // Prepare empty object to hold index reference
        idx = {};
    
    // Loop through the select elements and build index reference
    selects.each(function(i){idx[this.id] = i;});
    
    // Get select elements after #foo
    console.log(selects.slice(idx.foo+1));
    
    // Get select elements before #baz
    console.log(selects.slice(0, idx.baz));
    

    Check out the above method in this fiddle.

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

Sidebar

Related Questions

SELECT bar.*, baz.foo FROM bar LEFT JOIN baz if I have a column called
Here's a Rails2 query: Foo.find_by_bar_and_baz('a-bar', 'a-baz', :select =>'count(*) as the_count' ).the_count.to_i The query is
I want to do something like this: SQL.Text := Format('select foo from bar where
I know I can SELECT 5 AS foo and get the resultset: foo 5
I have a a hash foo = {'bar'=>'baz'} I would like to call foo.bar
Consider the following JPQL query: SELECT foo FROM Foo foo INNER JOIN FETCH foo.bar
I have an entity called Foo. It has a nullable many-to-one association to Bar.
Right now I'm running SELECT formula('FOO') FROM table1 WHERE table1.foo = 'FOO' && table1.bar
In MySQL I could execute the following: SELECT spam AS foo, eggs AS bar
I've just discovered that Oracle lets you do the following: SELECT foo.a, (SELECT c

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.