jqueryclickslideslidetoggle

How to make a closing a sliding div when you click outside of it?


Please help me! I create a simple sliding block and I'm trying to make it close when you click anywhere on the page, except for sliding "black" content.

See JSFiddle: jsfiddle.net/2DaR6/233/

Javascript

$(".black ").hide();
$(".white").show();
$('.white').click(function(){
    $(".black ").slideToggle(150);
});

HTML

<div class="black">
    content
</div>

<a href="#" class="white">click me!</a><br />

Solution

  • Something like this perhaps http://jsfiddle.net/HE2Qg/

    $(".black ").hide().click(function(){
        return false;
    });
    $(".white").show().click(function(){
        $(".black ").slideToggle(150);
        return false;
    });
    $(document).click(function(){
        $(".black ").slideUp(150);
    });