0

I searched through stackoverflow and various other sites and can't seem to get an answer to this dilemma.

My aim is to have jQuery functions applied to divs in succession using an array with div id's.

I have the following code that isn't working for some reason:

$(document).ready(function(){
    $('#click').click(function(){ 
        var layout_list = ['1','2','3','4','5','6','7','8','9','10'];
        load_delay = 50;
        for (i = 0; i < layout_list.length; i++ ) {
            load_delay =  load_delay+50;
            setTimeout(function(){
                $("#l_"+layout_list[i]).css("visibility","visible");
                $("#l_"+layout_list[i]).addClass("bounceIn");
            },load_delay);
        }
    });
});
2

1 Answer 1

1

You have to use a closure, e.g:

for (i = 0; i < layout_list.length; i++) {
    load_delay = load_delay + 50;
    (function (i) {
        setTimeout(function () {
            $("#l_" + layout_list[i]).css("visibility", "visible");
            $("#l_" + layout_list[i]).addClass("bounceIn");
        }, load_delay);
    }(i));
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. I feel like a complete noob now. I have it up and running now.

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.