<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<button class="show" aria-haspopup="true">Show Modal</button>
<div class="mask" role="dialog"></div>
<div class="modal" role="alert">
<button class="close" role="button">X</button>
</div>
<script>
// Click function for show the Modal
$(".show").on("click", function(){
$(".mask").addClass("active");
});
// Function for close the Modal
function closeModal(){
$(".mask").removeClass("active");
}
// Call the closeModal function on the clicks/keyboard
$(".close, .mask").on("click", function(){
closeModal();
});
$(document).keyup(function(e) {
if (e.keyCode == 27) {
closeModal();
}
});
</script>