Close pop up when click anywhere on the screen

Hi all,
I try to close the pop up using this example code
$(document).click(function (e) {

however when I click on the DHTMLX grid, it does not work, any idea?

You can try to attach event handler for capturing phase of event processing

document.addEventListener("click", function (e) { window.parent.parent.closePopup(); }, true);

Hi Stanislav,
Thanks for your help