Is it possible to load a newly cloned modal with bootstrap?
I'll need to load a lot of different modals, but below is an example of trying to load just one new modal.
I've seen questions on loading cloned elements within a modal, but not fully cloned modals.
Here is a fiddle with the issue: http://jsfiddle.net/hde13s2t/6/
Steps:
User click "Clone" to clone modal
Javascript clones modal and renames appropriate tags to "Clone" (button and modal tags)
User clicks the cloned modal --> "Launch demo modal 2"
The html all loads appropriately, but the new modal does not fire.
HTML:
<!-- Button trigger modal -->
<div id="launchmodal1">
<button type="button" class="btn btn-primary" data-toggle="modal" id="examplemodalbutton1" data-target="#exampleModal1">
Launch demo modal 1
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal1" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
</div>
<button type="button" class="btn btn-secondary" id="clicktoclone">Clone</button>
Javascript:
$(document).on("click", "#clicktoclone", function() {
var secondmodal = $("#launchmodal1").clone();
// updating button id and data-target for modal 2
secondmodal.find("#examplemodalbutton1").attr("id", "examplemodalbutton2").attr("data-target", "exampleModal2").html("Launch demo modal 2");
// updating modal id for modal 2
secondmodal.find("#exampleModal1").attr("id", "examplemodal2");
secondmodal.appendTo('#launchmodal2');
});