I am attempting to add a modal to a page after the page has load via a button click (in the below I did it on document ready instead of a click). The modal is created by cloning another modal and then appending the clone to the DOM. The modal node appears in the DOM but the modal does not open when giving it .modal() commands. I have created a simple codepen that shows my code and will show it below.
Codepen: https://codepen.io/anon/pen/YxQrZG
HTML:
<div id="LocalModalArea">
<div class="modal fade" id="exampleModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<div id="myModalLabel" class="sideLineHeader">
<h2><span>Modal Header</span></h2>
</div>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
JS:
$("Document").ready(function () {
var newModal = $("#exampleModel").clone(true, true);
newModal.attr("id", "NewModelId")
$('#LocalModalArea').append(newModal)
$("#NewModelId").modal("show")
});
jQuerywhich is required by bootstrap, ifjQueryadded it seems to be working jsbin.com/pamiqac/edit?html,js,output