I’m trying to get a Bootstrap modal to load via ajax some html that creates a modal. This html will have jPlayer in it.
I absolutely cannot get the buttons to work for the audio in the modal no matter what I try.
Here’s how I’m loading the modal:
$(document).ready(function() {
$(".createmodal").click(function(){
$('<div class="modal hide fade"> ..modal html.. </div>').modal();
});
});
Here’s the example in jsfiddle — I skipped the ajax and just loaded the html straight into the modal creation.
I’ve tried using jquery’s .load method.
JSFiddle: http://jsfiddle.net/R5UDn/
Edit: I’ve tried putting the jplayer initialization in the modal code… the audio fires if I use autoplay, but the controls do not work.
I redid your code as an AJAX call in Plunker, and it seems to work for me (Chrome, FF):
Plunker
I made it so the body of the page now includes a modal directly and loads an html AJAX response (modal-jplayer.html) into the
.modal-bodyvia thedata-remoteattribute. The script to activate the jPlayer is appended to the modal-jplayer.html.HTML
modal-jplayer.html
I don’t really know how that compares to what you have in your actual development code – I just did it the way I might do it.
Otherwise, something that might be causing an issue could be the auto-focus which the Modal plugin employs. That can be disabled rather simply:
But like I said, as of now, it works for me in the Plunker demo without having to use this workaround.
Just a recommendation for future posts: If you’re using AJAX then please take the time to prepare a comparable AJAX example in either JSFiddle or Plunker, or whatever you prefer. JSFiddle supports AJAX via GitHub Gists. Personally I prefer Plunker for anything AJAX because it supports multiple files directly in the app.