Hide element on page click?

Hi everyone,
On my site I have custom menu boxes that appear when users click a button in the header.
I’m wondering if there is a way to write some code that will hide the box whenever a user clicks outside the boxes . I tried adding a click event to the page, but this created a pointer cursor on the whole page, which I don’t want.
Is there another way to do this?

$w.onReady(() => {
    $w("#page1").onClick((event) => {
            $w("#menuBox1, #menuBox2").hide();
    });
})

Have you tried onBlur() on the boxes?

Just tried it, and it says onBlur does not exist for those elements

Yes, you’re right, just checked. Sorry about that. Nothing else comes to mind, maybe someone else has a bright idea.