1

I've run into a problem that I cannot figure out:

$(doc).ready(function(){
    $("span").html("<span>No</span>");

    $("button").click(function(){
        $("span").html(getRandomInt(50, 200));
        $(this).fadeOut(500);
        $("#title").delay(501).css({'margin-bottom': '110'});
    });
});




var doc = document;

var rand = Math.floor(Math.random()) * 259;

function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

Why does the .delay(501) in the $("#title") not work? the .css() works, just not the delay.

1 Answer 1

2

Because .css() function does not work based on a queue, it is a synchronous operation....

Looks like you are trying to set the margin property after the button is faded out, so use the complete callback method provided by jQuery

$("button").fadeOut(500, function(){
    $("#title").css({'margin-bottom': '110'});
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, worked great. I'll be sure you vote best answer when I can.

Your Answer

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