The following approach is much simpler. Listen for clicks on the entire page (using 'html' instead of 'body' since the body may not extend all the way down the page if the content is short). Then, also listen for clicks on your control, and stop the event from bubbling up to the 'html' handler:
$('html').click(function()
{
// Run the code, such as hide a menu or close a custom control
});
$('#custom_control').click(function(event)
{
event.stopPropagation();
});
Source: http://stackoverflow.com/questions/152975/how-to-detect-a-click-outside-an-element/153047#153047
0 comments:
Post a Comment