Re-set window.setInterval function with onClick

Posted on 2012-09-04
Last Modified: 2012-09-18
I have a function that I want to run on a set interval, once there is a click action on a specific target I want to do something and then reset the interval of the function.

window.setInterval(function faded(){
// Keep doing something and then reset me with onclick
}, 3000);

$(".target  li a").click(function(){

if(clickTrack == 0) {
// Do something and then
setInterval("faded()", 1000);

}else if(clickTrack == 1) {
// Do something and then
setInterval("faded()", 1000);

Open in new window

Question by:gvilla23
    1 Comment
    LVL 50

    Accepted Solution

    Save the return from SetInterval, call clearInterval with that ID and then call setInterval again


    var id = setInterval("doSomething()", 3000);

    $(".target  li a").click(function(){
    if(clickTrack == 0) {
    // Do something and then
    id = setInterval("faded()", 1000);

    }else if(clickTrack == 1) {
    // Do something and then
    id=setInterval("faded()", 1000);

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now