Skip to content Skip to sidebar Skip to footer

Modal Not Showing In Html File

I know this is not a rare problem, but I can't find a solution yet. I just want to show the modal when I click the button using JavaScript. But it always shows an error when I clic

Solution 1:

You need add these css and javascript library at head tag

<linkrel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

functionmyFunction() {

     $("#exampleModal").modal()
    }
<linkrel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script><tablestyle="width: 100%;"id="example"class="table table-hover table-striped table-bordered"><thead><tr><th>Name</th><th>Position</th><th>Office</th><th>Age</th><th>Start date</th><th>Salary</th></tr></thead><tbody><tr><td>Airi Satou</td><td>Accountant</td><td>Tokyo</td><td>33</td><td>2008/11/28</td><td><buttononclick="myFunction()">
              Basic Modal</button></td></tr></tbody></table><!-- this is my modal --><divclass="modal fade"id="exampleModal"tabindex="-1"role="dialog"aria-labelledby="exampleModalLabel"aria-hidden="true"><divclass="modal-dialog"role="document"><divclass="modal-content"><divclass="modal-header"><h5class="modal-title"id="exampleModalLabel">Modal title</h5><buttontype="button"class="close"data-dismiss="modal"aria-label="Close"><spanaria-hidden="true">&times;</span></button></div><divclass="modal-body"><pclass="mb-0">This is sample modal.</p></div><divclass="modal-footer"><buttontype="button"class="btn btn-secondary"data-dismiss="modal">Close</button><buttontype="button"class="btn btn-primary">Save changes</button></div></div></div>

Solution 2:

Include bootstrap and Jquery library in your head tag to make it work.

<linkrel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

Solution 3:

This issue is related to the jQuery/JavaScript file not added to the HTML file properly. This goes out and gets the jQuery code from the source. You could download that and reference it locally on the server which would be faster.

Or either one can directly link it to jQuery or GoogleCDN or MicrosoftCDN.

and also add this files-

<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

and write -

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

Solution 4:

It works! The problem is my template.If used bootstrap 3.4.1 the modal didn't show but when I replace and change it to bootstrap 4.5.2 it works now and it shows the modal. the problem is the version of the bootstrap I used.

Post a Comment for "Modal Not Showing In Html File"