Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Modal doesn't show

I wanted to test out Bootstrap's modal element and created a little test page. But nothing shows up and I'm wondering why, any clues? I got the source from the bootstrap page... My test page is at http://ronhome.no-ip.org/bootstrap/modal.html

like image 240
stdcerr Avatar asked Dec 09 '13 04:12

stdcerr


People also ask

How do I show a Bootstrap modal?

To trigger the modal window, you need to use a button or a link. Then include the two data-* attributes: data-toggle="modal" opens the modal window. data-target="#myModal" points to the id of the modal.

How do I know if a Bootstrap modal is open?

How check modal is open or not in jQuery? You can simply use the modal('show') method to show or open the modal window in Bootstrap using jQuery. Other related Bootstrap's modal methods are modal('hide') and modal('toggle') .

How do I show the modal in the center of the page?

Example 1: First, we will design modal content for the sign-up then by using CSS we will align that modal centered(vertically). Using the vertical-align property, the vertical-align property sets the vertical alignment of an element.

How do I show Bootstrap modal pop in center of screen?

Answer: Use the CSS margin-top Property This solution will dynamically adjust the alignment of the modal and always keep it in the center of the page even if the user resizes the browser window.


2 Answers

first thing you need to include jquery, and also trigger the modal, either with a button -

<button type="button" data-toggle="modal" data-target="#myModal">Launch modal</button>

or show the bootstrap modal using jquery -

<script type="text/javascript">
$(document).ready(function(){
    $('.modal').modal('show');
});
</script>
like image 138
Anil Saini Avatar answered Sep 20 '22 01:09

Anil Saini


Your example doesn't have jQuery included.

Uncaught Error: Bootstrap requires jQuery 

You must include jQuery before including Bootstrap.

Also, Bootstrap Modal's need to either be toggled by some kind of control on the page, or by JavaScript: http://getbootstrap.com/javascript/#modals-usage

This means you either need a button with the appropriate data attributes, which would correspond to attributes set on your modal, or execute via javascript

via JavaScript:

$('.modal').modal('show')

Or via attributes on a control:

<button type="button" data-toggle="modal" data-target="#myModal">Launch modal</button>

EDIT: If you do this, you need to specify the target as the ID of the modal div

<div id="myModal" class="modal fade">
   <!--modal content here -->
</div><!-- /.modal -->
like image 29
damienc88 Avatar answered Sep 23 '22 01:09

damienc88