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?
Asked
Active
Viewed 163 times
1
![](../../users/profiles/4926817.webp)
Noam Hacker
- 3,845
- 7
- 30
- 52
![](../../users/profiles/3599803.webp)
user3599803
- 4,641
- 10
- 50
- 95
-
pls show us your code – Iceman Aug 15 '16 at 20:48
2 Answers
1
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.
![](../../users/profiles/6707289.webp)
techimperial
- 31
- 2
0
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
}
![](../../users/profiles/-1.webp)
Community
- 1
- 1
![](../../users/profiles/4926817.webp)
Noam Hacker
- 3,845
- 7
- 30
- 52
-
Is there a better way? I prefer not to store my handlers in vars just to bind them again – user3599803 Aug 15 '16 at 21:06
-
@user3599803 I have updated my answer with an alternative, let me know if it helps. – Noam Hacker Aug 16 '16 at 00:36
-
you could put script tags in a `div` letting the id="script_div". then use jquery to append or remove the `div` – Noam Hacker Aug 16 '16 at 17:25