How to detect a click everywhere except on a specific HTML element in jQuery

To detect a click everywhere except on a specific div and its content in jQuery, here is the code to insert.
The code below will hide the element with the ID #my_div when clicking anywhere else.
This is very useful if your element contains, for example, a login form…

clic-partout-ailleurs-jquery
Example of use: closing a submenu by clicking anywhere other than on it.