Timecircles trigger click on 0

239 views Asked by At

I'm using Timecircles to build a simple quiz. Inside the "click" function I use .getTime() to get the actual time it took for the user to pick an answare.

However, I would like to "autoclick" (trigger the click-action) if the value of the time is 0. In order to move on to next question and set the number of points etc.

$(".countdown").TimeCircles({
    count_past_zero: false,
    total_duration: 15
    }).addListener(function(unit,value,total) {
        if(value == 0){
            alert ('GAME OVER!');
            //Trigger the click event here
        }
});
$('#quiz-container').on('click', '.my_button', function() {
    var t = $(".countdown").TimeCircles().getTime();
    //Quiz logic here

    // Load new question and reset timer
    var t = $(".countdown").TimeCircles().reset();
});

I can not place the click-function in the actual addlistener as I need to refresh it for each new question.

1

There are 1 answers

0
AmmarCSE On

Use trigger like

$('#quiz-container').trigger('click');

or the shorthand form

$('#quiz-container').click();

So, you will have

$(".countdown").TimeCircles({
    count_past_zero: false,
    total_duration: 15
    }).addListener(function(unit,value,total) {
        if(value == 0){
            alert ('GAME OVER!');
            //Trigger the click event here
            $('#quiz-container').click();
        }
});