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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:06:18+00:00 2026-05-22T16:06:18+00:00

These are 4 buttons I have on my webpage below is the code: <div

  • 0

These are 4 buttons I have on my webpage below is the code:

<div id ="topbar" width="80%; height:20px;" style="text-align:center">
    <input type="button" value="Click first" onclick="button.toggle();"></input>
    <input type="button" value="Click second" onclick="button2.toggle();"></input>
    <input type="button" value="Click third" onclick="button3.toggle();"></input>
    <input type="button" value="Click fourth" onclick="button4.toggle();"></input>
</div>

Currently when page is loaded, all of them are “on” (toggle does On or Off)
How do I turn them all off, and then loop them like this:

1 on rest off
2 on rest off
3 on rest off
4 on rest off
1 on rest off…. and it keeps looping.

I have tried this approach
Whats wrong with this?

setInterval ( "loop()", 2000 );

function loop ( )
{
setTimeout ( "SetLayer1()", 1000 );
}

function SetLayer1()
{
button.toggle(); //all off since all of them are on from start
button2.toggle();
button3.toggle();
button4.toggle();
}
function SetLayer2()

button.toggle(); // button 1 on rest off
//button2.toggle();
//button3.toggle();
//button4.toggle();
}
function SetLayer3()
{
button.toggle(); // button 1 off
button2.toggle(); //button 2 on
//button3.toggle();
//button4.toggle();
}
function SetLayer4()
{
//button.toggle();
button2.toggle();// button 2 off
button3.toggle();// button 3 on
//button4.toggle();
}
  • 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-22T16:06:19+00:00Added an answer on May 22, 2026 at 4:06 pm

    That’s elementary, Watson. Recursion. An example implementation can be like this:

    Make a variable holding all of your buttons and another variable called index (or something like that.) Then, make a function.

    Inside that function, you do a check. If there is a buttons[index] (index is not larger or smaller than the length of all your button’s array), make index=0. Then, toggle buttons[index] and increment index.

    You then call setTimeout – the first parameter being the name of the function, the second one being the amount of time you want to wait before firing it.

    Once outside of the function, call setTimeout in the same manner.

    Example: http://jsfiddle.net/bVNx2/

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

Sidebar

Related Questions

I have a webpage where there are two buttons and a textbox. When the
i have custom cell with 2 buttons(the function of these buttons is just to
I have a big table containing a button in each cell. These buttons are
i have this code below to show different divs when i choose certain radio
Some 'buttons' (divs with background images) on my webpage have shadow effects in the
I have 2 radio buttons in my mvc webpage. <% using (Html.BeginForm(Search, Search)) {
I have a fullcalendar that is loaded in a div in a webpage. when
I have 3 radio buttons in my web page, like below: <label for=theme-grey> <input
I have a jQuery Mobile webpage which currently has a width=device-width but my form
I have this simplified code: <div class=container> <input type=submit name=submit class=submit value=Sign Up> </div>

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.