tags:

views:

752

answers:

2

Here's the code I'm using

$(document).ready(function(){
        $('#slickbox').hide();
        // toggles the slickbox on clicking the noted link
        $('a#slick-show').click(function() {
            $('#slickbox').show('slow');
            return false;
        });

        // hides the slickbox on clicking the noted link

        $('a#slick-hide').click(function() {
            $('#slickbox').hide('fast');
            return false;
        });
        // toggles the slickbox on clicking the noted link

        $('a#slick-toggle').click(function() {
            $('#slickbox').toggle(400);
            return false;
        });
    });

Here's the HTML code:

<div id="slickbox"> BLARGH</div>
<a href="#" id="slick-show">Show</a>
<a href="#" id="slick-hide">hide</a>
<a href="#" id="slick-toggle">toggle</a>

Show and Hide work perfectly fine. Blargh is hidden when the browser opens and I can show and hide it but clicking the links. My problem tho, is that when I click toggle, if briefly slides open to show blargh and then slides shuts. I can click it as many times as I want and it does the same thing. How do I get it to stay shown and then click it again to hide it?

+2  A: 
$('a#slick-toggle').click(function() {
    $('#slickbox').is(":visible") ? $('#slickbox').hide("fast") : $('#slickbox').show("slow");
    return false;
});

or you could trigger the clicks of the show/hide bindings, and that way you wouldn't have to change the implementation of a#slick-toggle should you decide to change the animations:

$('a#slick-toggle').click(function() {
    $('#slickbox').is(":visible") ? $('a#slick-hide').trigger("click") : $('a#slick-show').trigger("click");
    return false;
});
karim79
A: 
$('a#slick-toggle').toggle(function() {
            $('#slickbox').show();
            return false;
        }, function() {
            $('#slickbox').hide();
        });
Daniel Moura