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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:31:23+00:00 2026-06-15T04:31:23+00:00

I am writing a simple breadcrumb inspired by https://stackoverflow.com/a/3834694/721084 . How I am trying

  • 0

I am writing a simple breadcrumb inspired by https://stackoverflow.com/a/3834694/721084. How I am trying to achieve this is by classifying each item by the page it would be on. The code below is meant to do that but it always ends up in an infinite loop. What am I doing wrong?

EDIT: Pastebin link to entire JS code http://pastebin.com/nxUhQmqF

Sample DOM:

<ul id="progress_bar" class="nostyle clearfix">
    <li class="first"><a href="">Blah</a></li>
    <li class=""><a href="">Blah</a></li>
    <li class="selected"><a href="">Blah</a></li>
    <li class="last"><a href="">Blah</a></li>
</ul>

JS Code:

    function classifyPages(bcParent, totalItems) {
    var pages       = 1,
        wd          = 0,
        parentWd    = findWidthOfParent(bcParent),
        crumbs      = bcParent.find('li'),
        i           = 0;

    for( i = 0; i < totalItems; i++) {
        wd = 0;
        while(wd < parentWd) {
            crumb = crumbs.eq(i);
            wd += crumb.outerWidth();
            if( wd < parentWd) {
                i += 1;
                crumb.addClass( 'bcPage-' + pages);
            }
        }

        pages += 1;
    }

    return pages;
}
  • 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-15T04:31:24+00:00Added an answer on June 15, 2026 at 4:31 am

    Your i, which is also incremented in the inner loop, will run above totalItems at some time. The non-existing crumb then has a outerWidth of 0 always, and you’re caught (as @Oleg V. Volkov described).

    This should work:

    function classifyPages(bcParent, totalItems) {
        var pages       = 1,
            parentWd    = findWidthOfParent(bcParent),
            crumbs      = bcParent.find('li');
    
        for (var i = 0; i < totalItems; i++) {
            for (var wd = 0; wd < parentWd && i < totalItems; ) {
    //                                     ^^^^^^^^^^^^^^^^^
                var crumb = crumbs.eq(i);
                wd += crumb.outerWidth();
                if( wd < parentWd) {
                    i += 1;
                    crumb.addClass( 'bcPage-' + pages);
                }
            }
            pages += 1;
        }
        return pages;
    }
    

    Better:

    function classifyPages(bcParent, totalItems) {
        var pages       = 1,
            parentWd    = findWidthOfParent(bcParent),
            crumbs      = bcParent.find('li'),
            wd          = 0;
    
        for (var i = 0; i < totalItems; i++) {
            var crumb = crumbs.eq(i);
            wd += crumb.outerWidth();
            if( wd >= parentWd) {
                pages += 1;
                wd = 0; // reset
            }
            crumb.addClass( 'bcPage-' + pages);
        }
        return pages;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing simple server/client and trying to get client IP address and save it
This is a really basic ruby gems question. I'm familiar with writing simple ruby
While writing a simple server-client application, this question came in my mind. When someone
I'am writing simple app. I want to run this app on many android devices
I'm writing simple menu module for Joomla! and at this point I'm working on
I am writing simple housekeeping script. this script contains following line of codes.This is
I'm writing simple solar system simulator. This is my first libgdx project. I'm using
I am writing simple parallel program in C++ using OpenMP. I am working on
I'm writing simple program to communicate between smart devices and I receive 11001 when
I'm looking into writing simple graphics code in Android and I've noticed some synchronized()

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.