1

I want a button pressed, then the button changes style, and a new function loads, after about 1/2 second of the styling.

$(document).on('click', '.capital_answers', function(){
    if(!$('#capital_answers').hasClass('answered')) {
        answer = $(this).attr('data-answer');
        if(answer==1) {
            $(this).addClass('capital_correct');
            $('#capital_answers').addClass('answered');
            capital_correct()
        }
        else {
            $(this).addClass('capital_wrong');
            $('#capital_answers').addClass('answered');
        }
    delay(500).capital_next();  
    }
});

So as you can see I am using the delay() method currently, which helps in no way. What options are there in delaying a function in this manner?

Source
  • 1,026
  • 4
  • 11
  • 23
  • `capital_next()` called with delay. So what is your problem? – Mohammad Jun 25 '16 at 22:38
  • what is `capital_next()`? is it a plugin? Is it a function? You have it chained to a function `delay()` which isn't even defined. Look in your console at errors thrown...what do you see? – charlietfl Jun 25 '16 at 22:39

1 Answers1

2

Use setTimeout()

Change:

delay(500).capital_next(); 

To

setTimeout(function(){
   capital_next();
}, 500);

this assumes that capital_next() is a standalone function. It's not clear from code in question

charlietfl
  • 170,828
  • 13
  • 121
  • 150