Bind function with Bootstrap Modal Close


Bind function with Bootstrap Modal Close : Sometimes we need to bind function with Modal close event. $(‘#modal’).on(); is used to bind a function with the close event. This method can be used to trigger the function when the close event occurs. Here in this tutorial we are going to explain how you can call function on modal close event. We will explain this with online demo.


Bind function with Bootstrap Modal Close

You can call function on bootstrap modal close event as below –

Bootstrap 3 : Call Function On Modal Close Event

If you are using the bootstrap 3 you can call a function on close event as below –

Bind function with Bootstrap Modal Close : Example

<script type="text/javascript">
$('#modal').on('hidden.bs.modal', function () {
    alert("Called on close button!");
});
</script>

Try it »

If you run the above example and click on the modal popup to close it trigger the alert on close event.

Bind function with Bootstrap Modal Close : Example

Bootstrap 2.3.3 : Call Function On Modal Close Event

If you are using the bootstrap 2.3.3 you can call a function on close event as below –

Call function on Bootstrap Modal Close Button Click : Example

<script type="text/javascript">
$('#modal').on('hidden', function () {
    alert("Called on close button!");
});
</script>

This will work same as the above example .


Advertisements

Add Comment

📖 Read More