$(\'body\').click(function() {
//hide layer code here
});
This will hide the layer.
But I don\'t want the layer to be hidden when I click insid
You can try something like this.
$(document).ready(function () { 
            $('body').click(function(e) {
                if(e.target.id !== 'layer') {
                    alert('Put code to hide layer here');
                }
            });
        });
    
This is layer
This is other part 
Demo
Also, you can create an overlay (the standard way)
HTML
This is layer
JS
$('#overlay').click(function(e) {
    alert('code to hide your layer'); 
    // Notice that this function won run when you click on layer but will run whenever you on any other part of body.
});
Demo