I have importaed javascript into my layout template:
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/js/bootstrap.min.js">
I have the following bootstrap modal triggered by a button
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<!-- Modal -->
<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" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
Did I forget to do something here? I have never done a bootstrap modal before but this should open a modal upon hitting the button correct? I thought it was because perhaps I was missing bootstrap javascript but I imported it from cloudflare min file and still doesn’t do anything. What I am missing?
2
Answers
You need to use a
script
tag for the bootstrap JS cdn not alink
tag like so:Also make sure you are using
jQuery
Bootstrap JavaScript is written in a script tag, not a link one. The link one is for CSS.
Yours:
It should be:
You also need to include jQuery like this
Otherwise your code is just fine!