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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:17:00+00:00 2026-05-25T21:17:00+00:00

http://jsfiddle.net/vol7ron/s5fS8/ HTML: <div class=container> <span class=foo>a</span> <span class=bar>1a</span> <span class=bar>2a</span> </div> <div class=container> <span

  • 0

http://jsfiddle.net/vol7ron/s5fS8/

  • HTML:

    <div class="container">
          <span class="foo">a</span>
          <span class="bar">1a</span>
          <span class="bar">2a</span>
    </div>
    <div class="container">
          <span class="foo">b</span>
          <span class="bar">1b</span>
          <span class="bar">2b</span>
    </div>
    <div class="container">
          <span class="foo">c</span>
          <span class="bar">1c</span>
          <span class="bar">2c</span>
    </div>
    
    <div class="title">Debug:</div>
    <pre id="debug"></pre>
    
  • JS:

    var debug      = $('#debug');
    var containers = $('.container');
    var foos       = containers.children('.foo');
    var bars       = foos.siblings('.bar:first');
    
    
    bars.each(function(){
        debug.append($(this).text() + '\n');
    });
    

What happens is the first bar is returned, whereas from an OOP POV, you’d think the first bar from each container would be returned.

As I left in a comment, I’m hung on why :first is applied to the result set, rather than the search set.


I thought the logic was: loop through the array of foos, find all the siblings that are bars, but only return the first one, add it to the array result stack, continue on to the next foo.

Instead, it’s: loop through array of foos, find all siblings that are bars, add them to the result stack, select the first one.

I think it should work more like find() where:

  • containers.find('.bar:first') returns the result I’m looking for
  • containers.find('.bar').first(':first') returns the result I’m currently getting (the OOP makes sense)
  • 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-25T21:17:01+00:00Added an answer on May 25, 2026 at 9:17 pm

    When you use first you are telling jQuery to get the first it finds from the list you give it not taking into account the parents. To get the result you ask about use this instead:

    var bars       = foos.next('.bar');
    

    Demo: http://jsfiddle.net/s5fS8/1/

    You can also loop over the containers instead:

    var debug      = $('#debug');
    var containers = $('.container');
    
    containers.each(function(){
        debug.append($(this).find(".bar:first").text() + '\n');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

http://jsfiddle.net/awfex/4/ HTML: <div class=section-header section-header-on id=section_header_289 style=left: 50px;> <span class=collapse></span> <div class=section-name> <span class=name>Testing
http://jsfiddle.net/vol7ron/bKWtM/ <body> <div id=head></div> <div id=body></div> <div id=foot></div> </body>   body { padding:0;margin:0;} #head
http://jsfiddle.net/55Ruh/9/ . Red box doesn't get bigger even if I enter text. <div class=box
http://jsfiddle.net/3NRsd/ var foo = $(div).bind(click, function() { $(div).animate({height : 500px}, 2000); $(div).animate({height : 50px},
http://jsfiddle.net/ZDydm/ Here is what I'm trying to do.. div { border: 1px solid black;
http://jsfiddle.net/ujTDf/1/ link text Can anybody help please. The div/form doesn't switsch automaticly in other
http://jsfiddle.net/aam7J/ How would I induce div-like behaviour on the input element? Specifically, how can
http://jsfiddle.net/n8YsM/ How do I make the div id blue take up the remaining visible
http://jsfiddle.net/hL6rT/1/ I've created div with a absolute positioned image inside it the idea is
http://jsfiddle.net/aBaw6/2/ This demo does not add class when you hover a list item. What

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.