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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:53:04+00:00 2026-06-09T01:53:04+00:00

I have created simple script with setInterval function and it is working fine on

  • 0

I have created simple script with setInterval function and it is working fine on first button click, but if I click my button couple of times my interval is queued up! I have tried to solve this using one function with Jquery but then I cannot set my Intereval again.
Is there a way to prevent this? Thank you!!

Fiddle example

My code:

 var changeClass=function(){

   if($('ul li.active').length==0){
   $('ul li:first').addClass('active');
   }
    else if($('.active').next().length==0){
       $('.active').removeClass('active');
       $('ul li:first').addClass('active');
    }
      else{
      $('.active').removeClass('active').next('li').addClass('active')
      }

 } 

$(document).ready(function() {
 var intervalID;
    $(".button").click(function(){
    intervalID=setInterval(changeClass,1000);
    });

      $(".clear").click(function(){
      clearInterval(intervalID);
      });

});
  • 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-09T01:53:05+00:00Added an answer on June 9, 2026 at 1:53 am

    So what are you actually trying to do? If you want the start button to be ignored when the interval is already set, write your click handler like this:

    $(".button").click(function() {
        if(!intervalID) {
            intervalID = setInterval(changeClass,1000);
        }
    });
    

    If you want the start button to restart the interval then you can issue a click on the clear button every time the start button is clicked like this:

    $(".button").click(function(){
        // Perform a click on the clear button
        $(".clear").click();
    
        intervalID = setInterval(changeClass,1000);
    });
    
    $(".clear").click(function(){
        clearInterval(intervalID);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Created a simple Jquery Code.. The Code is <script type=text/javascript> $('#Button1').click(function (evt)
I have created a simple expand/hide test script: <html> <head> <script type=type/javascript><!-- function showHide(elementid){
I have created simple script: #!/bin/sh column=${1:-1} awk '{colawk='$column'+1; print colawk}' But when I
I have created a simple JQuery script with hovering effect on some links. The
I have created two simple files in php. first file (i.e. input.php ): Created
I have created a simple bash script, chmod +x, and successfully am running it
I have created a simple perl script. The only thing it does is waiting
I have created super simple script as same as before when everything worked properly.
I have created a simple PHP script as a test. I want to have
I have created a very simple inno script through a wizard in InnoIDE. However

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.