I could swear I've used the double callback before on a toggle, but I
must be imagining it. Thanks Richard, I'll go the if statement route!

Gavin

On Nov 30, 4:54 pm, "Richard D. Worth" <rdwo...@gmail.com> wrote:
> Each of the methods you mention accept (optionally) a single callback
> function as a final argument. Neither accept more than one. See:
>
> http://docs.jquery.com/Effects/toggle#speedcallback
>
> http://docs.jquery.com/Effects/slideToggle#speedcallback
>
> If you want to do something different in one case as opposed to another,
> check whether the element is visible and then call the appropriate animation
> method to show or hide, along with anything else you want to do at the same
> time. Or call the toggle or slideToggle, and put your if inside the single
> callback, like so:
>
> $('#my-element').click(function() {
>   var wasHidden = $('#list-element').is(':hidden');
>   $('#list-element').slideToggle(200, function(){
>     if (wasHidden) {
>       $('#status-element').html('show artist index');
>       console.log('show');
>     } else {
>       $('#status-element').html('hide artist index');
>       console.log('hide');
>     }
>   });
>
> });
>
> - Richard
>
> On Mon, Nov 30, 2009 at 1:39 PM, Gavin <failed...@gmail.com> wrote:
> > I have a simple bit of jQuery that I just can't get working.
>
> > $('#my-element').click(function(){
> >                $('#list-element').slideToggle(function(){
> >                                $('#status-element').html('show artist
> > index');
> >                                console.log('show');
> >                        },function(){
> >                                $('#status-element').html('hide artist
> > index');
> >                                console.log('hide');
> >                        }
> >                );
> >        });
>
> > Right? Simple? I've had it working before, but whenever the element is
> > clicked, the element toggles but the console prints 'hide' every time
> > and the #status-element never gets changed. I have also tried just
> > using toggle() instead of slideToggle and also
>
> > slideToggle(200,function(){...
>
> > (including the speed before the callback functions).
>
> > Any ideas would be appreciated!
>
> > Thanks,
> > Gavin

Reply via email to