Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 / showing modal doesn't work with the javascript way

I use the Modal feature from Bootstrap 3.0.

I have this code:

<a data-toggle="modal" href="/myNestedContent" data-target="#myModal">
  Open the modal containing the content
</a>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
//nested content will be inserted here
</div>

When I click on the anchor (the link), the whole works => I see the modal with the content.

However, when I use the Javascript way (instead of the link) to show the modal like this:

$('#myModal').modal('show'); 

I only see the fade effect without the modal being shown...

When I started by clicking on the link, THEN calling the javascript, it works. (side effect?)

When I started by the javascript way, EVEN the link only shows the fade effect without the modal.

Might it be .. a bug from the modal Javascript method?

For information, the declarations of my scripts that I use are in the right order:

<script src="//code.jquery.com/jquery.js"></script>
<script src="javascripts/jquery.form.min.js"></script> 
<script src="javascripts/bootstrap.min.js"></script>
like image 309
Mik378 Avatar asked Aug 24 '13 22:08

Mik378


People also ask

Does Bootstrap 3 have modals?

The Bootstrap modal component allows you to add a stylized dialog box to your website. Add a stylized dialog box to your website with the Bootstrap modal component. Modals are created with the .

Can I use Bootstrap with JavaScript?

All Bootstrap's JavaScript files depend on util. js and it has to be included alongside the other JavaScript files. If you're using the compiled (or minified) bootstrap. js , there is no need to include this—it's already there.

Do you need jQuery for Bootstrap modal?

Bootstrap 5 is designed to be used without jQuery, but it's still possible to use our components with jQuery. If Bootstrap detects jQuery in the window object it'll add all of our components in jQuery's plugin system; this means you'll be able to do $('[data-bs-toggle="tooltip"]').tooltip() to enable tooltips.


1 Answers

i am not sure if i have misunderstood your question.

According to my understanding of your question, you need

$('#myModal').modal({
    show: true,
    remote: '/myNestedContent'
});

you cannot just

$('#myModal').modal('show'); 

because there is no url provided in this js method.

does this solve your question?

like image 173
Loonb Avatar answered Sep 21 '22 01:09

Loonb