Close dropdownmenu when clicking outside

Hi!
I´m building a dropdown menu and I want it to close when the user clicks anywhere outside the menu. I´ve looked at hittest but I can´´t figuring out how to implement it. Can anyone help me please?

Best regards
Tony