close modal on click code example

Example 1: on modal close jquery

$('#myModal').on('hidden.bs.modal', function () {
  // do something…
})

Example 2: data-dismiss= modal in jquery

$(document).ready(function(){
        // Open modal on page load
        $("#myModal").modal('show');
 
        // Close modal on button click
        $(".btn").click(function(){
            $("#myModal").modal('hide');
        });
    });

Example 3: javascript modal close

$('#closemodal').click(function() {
    $('#modalwindow').modal('hide');
});

Example 4: disable close from screen modal popup

<!-- opening with html, the key is the data-backdrop="static" attribute -->
<button data-target="#myModal" data-toggle="modal" data-backdrop="static" data-keyboard="false">
    Launch demo modal
 </button>
 
<script>
//Opening with JS:
$('#myModal').modal({backdrop: 'static', keyboard: false})  
</script>

Example 5: when modal close event

$("yourid").on('hide.bs.modal', function(){
	// do it here
});

Tags:

Html Example