Modal events not working for JQuery .on()
See original GitHub issueContext : Symfony 5.3.9 project / Boostrap 5.1.3
This works :
document.getElementById('myModal').addEventListener('hidden.bs.modal', function() { alert('ok'); });
This doesn’t :
$("#myModal").on('hidden.bs.modal', function() { alert('ok'); });
Same goes for any modal event. Did I miss something ?
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Bootstrap modal event not fired - Stack Overflow
I'm creating my modal's dynamically, so they don't exist on the page load. I'm adding them to the DOM with a JQuery .append('body')...
Read more >JQuery click event not working in bootstrap modal - YouTube
jQuery : JQuery click event not working in bootstrap modal [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] jQuery ...
Read more >JavaScript - Bootstrap
Use event.relatedTarget and HTML data-* attributes (possibly via jQuery) to vary the contents of the modal depending on which button was clicked. See...
Read more >Modal event.preventDefault() for show.bs.modal ... - GitHub
This is because the modal.js module sets the value for whether the modal is transitioning or not before it triggers the show.bs.modal event....
Read more >jQuery not working within my modal - Laracasts
I need to use jQuery to call a function on show of my Bootstrap Modal. Copy Code $('#Modal').on('show.bs.modal', function (event) {... This usually...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The detection depends on existence of
window.jQuery
. I guess, in some cases it might just not exist. As this is mentioned in https://getbootstrap.com/docs/5.0/getting-started/javascript/#still-want-to-use-jquery-its-possible (and #events) I suggest to close this ticket. Maybe every page mentioning addEventListener() should have a link (“How to do this with jQuery?”) to this getting started page section.ps. I once worked with
cash-dom
which is a tiny jQuery replacement. The way it was imported created onlywindow.$
.@UgoFlamarion Did you include jQuery? If not please include it and try again.
And if it doesn’t work, please create a https://codepen.io/ demo.