Avatar ·

How to detect click outside an element in JavaScript (without jQuery)?

Hello everyone! I'm a beginner frontend developer and I've encountered a typical task: I need to close a dropdown menu (or modal window) when clicking outside of it. \n\nI'm using pure JavaScript without jQuery. I have an HTML structure where clicking a button opens a `