In jQuery, you can easily chain actions for the same selector, but if you want to use a different selector for each action that requires a nested $.when with more than two actions that are pretty hard to read and maintain.
HTML:
<span id='a'>Hello</span> <span id='b'>world</span> <span id='c'>!!!</span>
CSS
span { display: none; }
JS: based on this: how to hide multiple elements, but only call the handler once?
var d = 500; // duration // Execute in parallel. //$('#a').show(d).hide(d); //$('#b').show(d).hide(d); //$('#c').show(d).hide(d); $.when($('#a').fadeIn(d).fadeOut(d)).done(function () { $.when($('#b').show(d).hide(d)).done(function () { $('#c').slideDown(d).slideUp(d); }); });
jsfiddle (old)
jsfiddle-2
I could use a queue , but it seems to work only for the same selector.
Is there a way to write it in a more convenient way, for example:
pseudo code
var myActions = []; myActions.push(function(){...}); myActions.push(function(){...}); myActions.push(function(){...}); something.executeSequentially(myActions);
EDIT:
I updated the demo to make it a little more complicated.
source share