How to hide div when clicked outside it?

    You can use the following code:
    var mouse_inside_div = false; //globally declared

    $(document).ready(function()
    {
        $('#div_id').hover(function(){   
            mouse_inside_div=true;
        }, function(){
            mouse_inside_div=false;
        });

        $('body').mouseup(function(){
            if(! mouse_inside_div) $('#div_id').hide();
        });
    });


    where #div_id is used as id of the div to hide when clicked outside it
    5
    Average: 5 (1 vote)