Chaining jQuery

Hi guys, I need help with chaining jQuery sequence

$('#counter')
    .fadeOut(0).delay(300).fadeIn(0).delay(300)
    .fadeOut(0).delay(300).fadeIn(0).delay(300)
    .fadeOut(0).delay(300).fadeIn(0);

This blinks an element three times and works as expected. How can I make it more DRY (as you can see it repeats the same commands), maybe using any kind of loop?

The first one with for-loop works, thank you.

I’m still not very familiar with all that Javascript asynchronous stuff, and I need to run it sequentially (in defined order). I read somewhere that I should not use functions inside for loop. Do you think it is safe to do this so that things wouldn’t execute asynchronously?

As for promises - I’m still only planning to learn them some day :slight_smile:

Wow, javascript is infinitely expressive. Thank you a lot!