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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:45:34+00:00 2026-06-11T18:45:34+00:00

The problem is that I do not know how to break the loop for

  • 0

The problem is that I do not know how to break the loop for the first number and start again for the next one. Currently, one span.nNumber has a total digits of the two numbers (123456) and the next span.nNumber contains digits only from another number (456).
Goal is to create sequence 123 and 456:

Markup:

<span class='nNumber'>
 <span>1</span>
 <span>2</span>
 <span>3</span>
</span> 

<span class='nNumber'>
 <span>4</span>
 <span>5</span>
 <span>6</span>
</span>

JavaScript (example):

$('div .number').each(function(){
    var number = $(this).text();
    var i = 0;

    $(this).parent().prepend($("<span class='nNumber'></span>"));
    while(i<number.length)
    {
        $(this).closest('span').hide();
        var nChar = number.charAt(i);  
        i++;
        $('.nNumber').append('<span class="digit-'+nChar+'">'+nChar.split(" ").join(", ")+'</span>');
    }
});​
  • 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-11T18:45:35+00:00Added an answer on June 11, 2026 at 6:45 pm

    In your while loop, use the following;

    $(this).parent().find('.nNumber').append('<span class="digit-'+nChar+'">'+nChar+'</span>');
    

    This way, you’ll always modify the nNumber class inside the div you are iterating over. If you use $(".nNumber") you’ll get all elements whose class is nNumber, even the ones that are not in your current div. That’s why the second iteration of .each() adds the extra digits 456 to the first span.

    DEMO.

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

Sidebar

Related Questions

I guess the problem is that I do not know how to use factory
I have a problem that someone introduced a bug but I do not know
I have working registration script the only problem is that i do not know
To be honest, I do not really know how to name that problem. I'll
I have a simple problem that I have not been able to find an
I have a strange problem that I could not solve. When I try to
I have a problem that I have not faced before: It seems that the
I faced a problem that I can not find a way to change the
Problem: to show that a Not-SO-page has been discussed in SO when you at
I've got the problem that the UIAlertViewDelegate method - (void)alertViewCancel:(UIAlertView *)alertView is not called

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.