Reputation: 125
I have the following bootstrap modal:
<div class="popupCover">
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria- labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" onClick="closeModal()" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span> </button>
</div>
<div class="modal-body">
<h4>Text1</h4>
<p>Text2</p>
</div>
</div>
</div>
</div>
</div>
I am trying to open it with
<script type="text/javascript">$('#myModal').modal('show')</script>
However, this does not work. Can anyone see the error? Thanks!
Upvotes: 0
Views: 718
Reputation: 4289
You should add jQuery and bootstrap.js files, and bootstrap script should be added after jQuery
You can see the working pen here
HTML:
<div class="popupCover">
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria- labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" onClick="closeModal()" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span> </button>
</div>
<div class="modal-body">
<h4>Text1</h4>
<p>Text2</p>
</div>
</div>
</div>
</div>
</div>
JS:
$('#myModal').modal('show');
Upvotes: 1