Assuming you are using the latest jQuery, v1.4.4:
$(<the div you want hidden>).click(false);
$(document).one('click', function(){
$(<the div you want hidden>).hide();
});
In other words, this code says: "Hide the div if you click on this page, if you don't click on the div."
Re: Toggle button
Then you will have something like:
$('button').click(function(){
$('div').toggle();
});
$('div').click(false);
$(document).click(function(){
$('div').hide();
$('button').removeClass('selected');
});
source
share