Hide element on click anywhere else apart of the element

To make a certain part clickable and then hide it when you click anywhere else, you need to check if your click place has certain class then show it otherwise hide it.
So we will check our click on whole document and then we will see if it has certain class attached to it or not. Like this :

(function ($) { 
// Check the click on whole DOM
$(document).on('click', function(e) {
       // Check if target has certain class
        if($(e.target).hasClass('YOU_CLASS_NAME')) {
        } else {