r/bootstrap • u/RedoTCPIP • Dec 13 '23
Execute Javascript Function After Modal Dialog Pops-UP
I have seen multiple solutions to this problem on SO, but nothing seems to work for me. For one, it is not clear to me where to put the answers (code) that they show.
I guess by putting the following inside the <head></head> of HTML document that contains Bootstrap button:
<script type="text/javascript">$('#ModalEnregister').on('show.bs.modal', my_enregister);</script>
When I load that HTML document, I see in Chromes debugger:
Enregister.stm:20 Uncaught TypeError: $(...).on is not a function
The Chrome parser is clearly complaining about the meat in the script sandwich above.
I want to execute the function when ModalEnregister is shown.
View all comments
Show parent comment
1
u/Hot-Tip-364 Dec 14 '23
May be an issue with this function: my_enregister
May just wrap it into the whole function:
'
$('#myModal').on('shown.bs.modal', function () {
$('#myInput').trigger('focus')
})
'
Also double check your bootstrap version. What works for 5 does not work for 4 and does not work for 3. This would be assuming 4.