0

I have the following code that I took off from a plugin. I have very less experience and knowledge with JavaScript. I am trying to delay the change of text in html. Here's what the code i have:

function printResult() {
    var res;
    var blah="OKAY B****!";
    
    if(win[a.pos] === win[b.pos] && win[a.pos] === win[c.pos]) {
        res = "You Win!";
    } else {
        res = "You Lose";   
    }

    $('#result').html(res);

    if(res=='You Lose'){
        setTimeout($('#result').html(blah),3000);
    }else{}
}

The text in #result changes but it changes instantly without the delay.

0

7 Answers 7

2
setTimeout(function(){$('#result').html(blah)},3000);
Sign up to request clarification or add additional context in comments.

Comments

1

Try this

setTimeout(function(){
  $('#result').html(blah)
},3000);

Comments

1
setTimeout(function(){
//your code
}, 3000 );

Comments

1

The function setTimeout take a function as first parameter :

setTimeout(function()
{
  $('#result').html(blah)
}, 3000 );

Or:

function update()
{
  $('#result').html(blah)
}
setTimeout(update, 3000);

Comments

0
setTimeout(function(){
  $('#result').html(blah)
},3000);

Comments

0

setTimeout requires a function to be passed as argument.

setTimeout(function() {
  $('#result').html(blah)
}, 3000);

Comments

0

Use either:

setTimeout("$('#result').html(blah)",3000);

or

setTimeout(function(){
  $('#result').html(blah)
},3000);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.