<div class="overlay">
<div class="your-dialog"></div>
</div>
.overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
}
.your-dialog {
z-index: 2;
}
<style>
.modal {
display: none
}
.modal.__show{
display: block
}
</style>
<button type="button" class="btn">toggle Modal</button>
<div class="modal" >Modal text</div>
$('.btn').on('click', function(){
$('.modal').toggleClass('__show');
})
$('body').on('click', function(e){
if(e.target !== $('.modal') && e.target !== $('.btn') && $('.modal').hasClass('__show') ){
$('.modal').removeClass('__show');
}
})