I have implemented the following piece that works almost everywhere on the page.
$(document).click(function(event){
if($("#div_to_close").is(":visible")){
$("#div_to_close").hide();
}
});
$("#div_to_close").click(function(event){
event.stopPropagation();
});
This is working fine anywhere on the page but there are certain elements on the page where click handlers are implemented and event.stopPropagation() is used in the hadler. In all such elements the div does not close.
This happens because the click event for these elements do not bubble upto the document and hence the handler for doc is not called.
How do I come across this?