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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:04:42+00:00 2026-05-16T22:04:42+00:00

I have a script that displays one div at a time while hiding the

  • 0

I have a script that displays one div at a time while hiding the previous shown div. When a button is clicked, the counter variable increases by one and the naming of the div id’s are “step1”, “step2”, “step3”, etc. Here is the script:

<script language="javascript" type="text/javascript">
        var counter = 0;
        $('html').addClass('js'); // prevent hiding divs on DOM ready from 'flashing'
        $(function() {
                $('#toggle_value').click(function() {
                $('div','#hiddendiv')
                        // to stop current animations - clicking really fast could originally
                        // cause more than one div to show
                        .stop()
                        // hide all divs in the container
                        .hide()
                        // filter to only the div in questio
                        .filter( function() { return this.id.match('step' + counter); })
                        // show the div
                        .show()
                        // prevent default anchor click event
                        return false;
                });
        });
</script>

This is where the variable is being incremented when clicked:

<div class="toggle_button">
        <a href="#" onClick="counter = counter + 1" id="toggle_value"></a>
</div>

Here is my hidden div:

<div id='hiddendiv'>
        <div id="step1" class="display">
                <p>step 1 text</p>
        </div>
        <div id ="step2" class="display">
                <p>step 2 text</p>
        </div>
        <div id="step3" class="display">
                <p>step 3 text</p>
        </div>
        <div id ="step4" class="display">
                <p>step 4 text</p>
        </div>     
        <div id="step5" class="display">
                <p>step 5 text</p>
        </div>
        <div id ="step6" class="display">
                <p>step 6 text</p>
        </div>     
        <div id="step7" class="display">
                <p>step 7 text</p>
        </div>
        <div id ="step8" class="display">
                <p>step 8 text</p>
        </div>     
        <div id="step9" class="display">
                <p>step 9 text</p>
        </div>
        <div id ="step10" class="display">
                <p>step 10 text</p>
        </div>     
        <div id="step11" class="display">
                <p>step 11 text</p>
        </div>
</div>

The script works wonderfully and does what it needs, until id’s with double digits and ending with a “0” (10, 20, 30, 40, etc…). For example: when the counter = 1, div id step1 and div id step10 are being shown on the page. When the counter = 10, only div id step10 is being shown. Div id step11 is shown at the appropriate time so I have narrowed it down to double digits ending in 0. I will never have more than 100 steps so only ending double digits or less are being used.

Are 0’s at the end of a div id being ignored and being seen step1 and step10? I know you can’t use a numeric value at the beginning of a id but it also states any number of [0-9] after the alphabetic character.

Thank you

  • 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-16T22:04:43+00:00Added an answer on May 16, 2026 at 10:04 pm

    Instead of using match(), just check for equality:

    // filter to only the div in question
    .filter( function() { return this.id == 'step' + counter; })
    

    Example: http://jsfiddle.net/TAQZQ/

    match() is intended for searching a string with a regular expression and returning the matches.

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

Sidebar

Related Questions

I have the script shown below that displays a list of records from a
I have a script that displays countries in different languages. For example United Kingdom
I have a script that uses a simple while loop to display a progress
I have a script that takes a while. I'd like to display a page
I have an open cart site that displays all the products on one page
I have script that reads remote file content and writes it to local server.
I have this script that run to fix my menu bar to the browser
I have a script that recursively loops through all the sub directories and compresses
I have a script that submits data via an ajax POST. It is called
I have following script that executes all the .reg files in the current directory.

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.