Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap $('#myModal').modal('show') is not working

Tags:

I'm not sure why but all the modal functions are not working with me. I checked the version and the load they are fine.

I keep getting this error message:

Uncaught TypeError: $(...).modal is not a function

for the hide I already found an alternative. instead of:

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

I used this :

$('#myModal .close').click(); 

And it works perfectly.

The problem now is with the show

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

I also tried both

$('#myModal').modal("toggle"); 

And:

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

but unfortunately none of them is working.

Here html code -when the button is clicked I will do some verification and handle a json data from the web service if it succeed then I want show my modal- everything is working except the show.

 <button type="button" id="creatNewAcount" class="btn btn-default" data-toggle="modal">Sign up</button> 

if there's any alternative I would like to know it.

like image 364
Nysa Avatar asked Apr 17 '16 03:04

Nysa


People also ask

Is Bootstrap 5 released?

Bootstrap 5 has officially landed! After three alphas, three betas, and several months of hard work, we're shipping the first stable release of our new major version.

What is Bootstrap min JS?

Bootstrap is a free front-end framework for faster and easier web development. Bootstrap includes HTML and CSS based design templates for typography, forms, buttons, tables, navigation, modals, image carousels and many other, as well as optional JavaScript plugins.

How do I connect Bootstrap locally?

Under the folder, copy the extracted files downloaded from bootstrap. Under the head tag of the HTML file, the CSS needs to be linked. The jQuery downloaded should also be copied under the JS file. Make sure that under the project file, the downloaded files and HTML page must be present in that folder.

What is Bootstrap CDN used for?

BootstrapCDN is a public content delivery network. It enables users to load CSS, JavaScript and images remotely from its servers. Used by more than 7.9 million websites worldwide (including 30% of the top-10k websites), BootstrapCDN serves more than 70 billion requests a month.


1 Answers

Most common reason for such problems are

1.If you have defined the jquery library more than once.

<script type="text/javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>      <div class="modal fade" id="myModal" aria-hidden="true">     ...     ...     </div>  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> 

The bootstrap library gets applied to the first jquery library but when you reload the jquery library, the original bootstrap load is lost(Modal function is in bootstrap).

2.Please wrap your JavaScript code inside

$(document).ready(function(){}); 

3.Please check if the id of the modal is same

as the one you have defined for the component(Also check for duplication's of same id ).

like image 99
Prakash Thete Avatar answered Oct 18 '22 15:10

Prakash Thete