jonmrich
jonmrich

Reputation: 4323

Execute function when modal is shown

I'm using Bootstrap and using this to show a modal after a click event:

$('#make_selects_modal').appendTo("body").modal('show');

I need to be able to execute a function (called pickClient) when this is shown. I tried something like this, but it doesn't work. Not sure of the correct syntax.

$('#make_selects_modal').appendTo("body").modal('show').pickClient();

Upvotes: 0

Views: 102

Answers (2)

DavidG
DavidG

Reputation: 118937

From the Bootstrap documentation you can use events for this, specifically in your case the shown.bs.modal event:

$('#make_selects_modal').on('shown.bs.modal', function () {
    pickClient();
})

Upvotes: 2

Ben Fortune
Ben Fortune

Reputation: 32117

When the modal is visible, an event called shown.bs.model is fired.

You can use

$('#make_selects_modal').on('shown.bs.modal', pickClient);

Modal event docs.

Upvotes: 4

Related Questions