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

  • Home
  • SEARCH
  • 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 6206513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:27:50+00:00 2026-05-24T05:27:50+00:00

Is jQuery’s each() function non-blocking? In the below example, I expect test in each

  • 0

Is jQuery’s each() function non-blocking?

In the below example, I expect “test in each” to be logged first, but in each test “test out of each” is logged first.

So this is causing the loop to run up to the body (sometimes the document) element before returning an error.

I’m just trying to get a common parent to wrap or if the two elements (firstp and lastp) are the siblings, then wrap those.

But, I’m mostly curious about the performance of the each() function and whether it is non-blocking.

while(firstp[0] !== lastp[0]){
        //If parents are siblings, this will do for wrapping.
        var isS = false;
            firstp.siblings().each( function(index, el){
                console.log("test in each");
                if(jQuery(el)[0] === lastp[0]){
                    isS = true;
                    return true;
                }
            });
            console.log("test out of each");
        if(isS === true){ break; }
        firstp = firstp.parent();
        lastp = lastp.parent();
    }

EDIT:

Sorry guys. This was a false alarm. Paul is correct. My HTML actually had two elements that was matching for firstp. I didn’t realize this, so the first one did not have a sibling, causing the error. I was looking at the second element the whole time.

But, I did learn something in the process, so thanks for taking the time to answer.

  • 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-24T05:27:52+00:00Added an answer on May 24, 2026 at 5:27 am

    .each() is synchronous. My guess is this:

    On the first iteration of your while loop firstp has no siblings so the object being iterated by each is empty and “test out of each” is the first thing logged. Then on the second iteration firstp has siblings so it enters the each and you immediately see “test in each” being printed after “test out of each”.

    I think you will see the proper behavior from console if you change your code to something like this, so you can see what iteration the loops are on:

    var i = 1;
    while(firstp[0] !== lastp[0]){
            //If parents are siblings, this will do for wrapping.
    
            var isS = false;
                firstp.siblings().each( function(index, el){
                    console.log(i+": test in each ("+index+")");
                    if(jQuery(el)[0] === lastp[0]){
                        isS = true;
                        return true;
                    }
                });
                console.log(i+": test out of each"));
                i++;
            if(isS === true){ break; }
            firstp = firstp.parent();
            lastp = lastp.parent();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

jQuery('td[class=bgoff]').each(function() { var td = jQuery(this); ... no apply selector to this only });
jQuery(document).ready(function(){ $(function() { $('.button-a').each(function() { $(this).hover( function () { $('.button-title', this).animate({ opacity: 0.6 },
Jquery has a great language construct that looks like this: $(document).ready(function() { $(a).click(function() {
jQuery.get(window.location.href, function(data) { alert(data); alert($(data).html()); }); The first popup is all the HTML good
jQuery(function() { jQuery(ul.logos-sprite-icon-wrap li a.logos-icon).hover(function() { jQuery(this).animate({ 'padding-top': '0px', 'padding-bottom': '5px', }, 500); },
jQuery can return last or first child,it works ok. But I need to get
Jquery Code: $(.tog).toggle( function() { $(.tog span).removeClass('stog'); $(.tog span).addClass('stogm'); $(this).next().slideDown('fast'); }, function() { $(.tog
jQuery: $(.upvote).click(function() { var id = $(this).attr('id'); var changeImage = ($(this).children('img').attr('src') === siteUrl +
Jquery UI Dialog modal-form doesn't shows up inside table, but works fine outside. This
jQuery(document).ready(function () { $lstAccountType = $('select[id*=account_type]'); $lstAccountType.change(function () { $(this).remove('option[text=select one]') }); }); I

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.