Skippy Skippy - 11 months ago 73
Javascript Question

get bootstrap modal element id on

I am looking to return the element ID of the currently being hidden modal in bootstrap. I cannot seem to find a way to capture this via this code:

$(document).on('', function (e) {

// I want to know what the attr ID is of THIS modal being closed?
// I tried console.log(e) to see if I could find the reference but its not in the object?


The purpose is to have this for all modals, some modals contain input fields, if changed to a dirty flag I can alert the user that data loss may occur if they close this modal.


If you log the event you receive inside that handler function, you'll notice there is a target node on their that contains the actual modal. So getting the id should be as simple as:

var id =;

have a look at the demo I set up:
On close you'll see the modal id in the console.