1

I am trying to discover if it is possible to use the .queue() method in JQuery with multiple selectors in the same queue.

I can't find any examples of where things are added to the same queue from different selectors.

for example:

$('#aDiv').queue(function() {
$(this).fadeOut(1000);
});

$('#someOtherDiv').queue(function() {
$(this).fadeOut(1000);
});

I want these to occur sequentially, but they appear to be happening concurrently. I have tried creating named custom queues, but that makes no difference.

Is this even possible?

Thanks

Daybo
  • 13
  • 3
  • 1
    are you trying to learn `queue` or would you like an attempt at a different solution for fading in/out sequentially? – Phil Jul 18 '11 at 14:19
  • Thanks Phil, I'm trying to use queue if at all possible. – Daybo Jul 18 '11 at 14:20
  • I can't answer properly right now, but I think you've misinterpreted what `queue()` is used for. – Rudi Visser Jul 18 '11 at 14:22
  • Maybe I have, but from my understanding queue can be used to create a series of events to be executed in order one after the other. And that is what I need to achieve. If there is a better method to use I would be happy to use it. – Daybo Jul 18 '11 at 14:25
  • 1
    I agree with Phil. My personal feeling on this is that queue() is not the way to go so unless you're trying to learn queue() for some macabre or masochistic reason then I'd do it another way i.e. using the callback feature of fadeOut() – kasdega Jul 18 '11 at 14:30

3 Answers3

2
$('#aDiv').fadeOut(1000, function(){
   $('#someOtherDiv').fadeOut(1000); 
}); 

Use the callback.

Robert de W
  • 316
  • 8
  • 24
  • He doesn't want to use `fadeOut()` – Phil Jul 18 '11 at 14:36
  • he says he just wants to "create a series of events to be executed in order one after the other" and the example he gives is using fadeOut. This is correct given the question asked. – kasdega Jul 18 '11 at 14:38
  • "I am trying to discover if it is possible to use the .queue() method " – Phil Jul 18 '11 at 14:48
  • Thanks Robert - I ended up using the callback, although I would have preferred to use the .query() because from what I understand this is more useful in complex situations where there are many actions required, and the callback method could get quite cumbersome. However, for this situation the callback will work. So thank you all for your help. – Daybo Jul 19 '11 at 00:02
0

I don't think that queue is used to "queue" events: it's justa a way to retriev the queue of events attached to an element (look at the example in the documentation ). If you want to queue events, you must do other things

Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192
0

If you want to learn everything that is to learn about queue() read this: queue explained

Community
  • 1
  • 1
Phil
  • 10,948
  • 17
  • 69
  • 101