user3599803
user3599803

Reputation: 7004

bootstrap modal hide method - silent without event?

I want to call modal("hide") in a 'silent' way - i.e. not to trigger the event handlers which I attached using .on("hidden.bs.modal"). How?

Upvotes: 1

Views: 244

Answers (2)

techimperial
techimperial

Reputation: 31

Maybe you could use a var isSilent inside your on hide event and have an if silent do nothing else do stuff, rather than trying to unbind events.

Upvotes: 1

Noam Hacker
Noam Hacker

Reputation: 4825

I would unbind the event handler, hide the modal, and then re-bind the event handler. See this question for the best ways to remove an event handler.

The answer demonstrates using the jquery off() function like so:

$('#myimage').on('click.mynamespace', function() { /* Do stuff */ });
$('#myimage').off('click.mynamespace');


Alternative:

Temporarily override your trigger somewhere in your code, and then remove that piece of code when you are done:

.on("hidden.bs.modal") { //do nothing }

Upvotes: 0

Related Questions