Objective:
I have a bootstrap modal:
- I want to make a function call when this modal hides.
- I want to call this function only once when the modal closes.
Note:
I'm using Bootstrap 3.
Problem:
- I cannot make changes to the HTML.
- The HTML has dynamic class names ex:js123, js456 etc.
- There is no unique class name or id for the modal itself.
Sample Code:
<body class="app-body">
<div role="presentation" class="jss20" style="position: fixed; z-index: 1300; inset: 0px;">
<div aria-hidden="true" style="z-index: -1; position: fixed; inset: 0px; background-color: rgba(0, 0, 0, 0.5);"></div>
<div tabindex="0" data-test="start"></div>
<div class="jss942 modal-content" tabindex="-1">
<div class="jss946">
<div class="jss950">
<span id="newdata-modal-title">New Data 1</span>
...
</div></div></div></div></div></div></body>
I've tried the following with no luck:
$('div.modal-content').one('hide', function () {
onhideCall(param1, param2);
});
$('div.modal-content').on("hide.bs.modal", function () {
onhideCall(param1, param2);
});
$('div[role="presentation"].modal-content').click(function(){
onhideCall(param1, param2);
});
$('div[role="presentation"]').on("hide.bs.modal", function(){
onhideCall(param1, param2);
});
Another problem I am facing is that there are multiple classes with name "modal-content". That could be a problem too?.
See the following chrome console output:
>>$('.modal-content')
m.fn.init(17)?[div.modal-content, div.modal-content, div.modal-content, div.modal-content, div.modal-content, div.modal-content, div.modal-content, div.modal-content, div.modal-content, div.modal-content, div.modal-content, div.modal-content, div.modal-content, div.modal-content, div.modal-content, div.modal-content, div.jss942.modal-content, prevObject: m.fn.init(1), context: document, selector: ".modal-content"]
Can someone please help me out here? Thanks very much in advance. Your help is highly appreciated.
question from:
https://stackoverflow.com/questions/65928687/how-to-trigger-a-function-call-in-jquery-when-bootstrap-modal-hides-if-my-modal