🌐
W3Schools
w3schools.com › bootstrap5 › bootstrap_modal.php
Bootstrap 5 Modal
Change the size of the modal by adding the .modal-sm class for small modals (max-width 300px), .modal-lg class for large modals (max-width 800px), or .modal-xl for extra large modals (max-width 1140px). Default is 500px max-width.
🌐
W3Schools
w3schools.com › bootstrap › bootstrap_modal.asp
Bootstrap Modal Plugin
To trigger the modal window, you need to use a button or a link.
🌐
Bootstrap
getbootstrap.com › docs › 5.0 › components › modal
Modal · Bootstrap v5.0
Clicking on the modal “backdrop” will automatically close the modal. Bootstrap only supports one modal window at a time.
🌐
Bootstrap
getbootstrap.com › docs › 5.3 › components › modal
Modal · Bootstrap v5.3
Embedding YouTube videos in modals requires additional JavaScript not in Bootstrap to automatically stop playback and more. See this helpful Stack Overflow post for more information. Modals have three optional sizes, available via modifier classes to be placed on a .modal-dialog.
🌐
W3Schools
w3schools.com › bootstrap5 › tryit.asp
Click on the button to open the modal.
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
W3Schools
w3schools.com › bootstrap5 › index.php › bootstrap_modal.php
Bootstrap 5 Tutorial
Start Bootstrap 5 Quiz! View your completed tutorials, exercises, and quizzes ... Note: This is an optional feature. You can study at W3Schools without creating an account.
🌐
W3Schools
w3schools.com › bootstrap5 › tryit.asp
W3Schools online HTML editor
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
W3Schools
w3schools.com › bootstrap5 › tryit.asp
Vertically Centered Modal Example
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
W3Schools
w3schools.com › bootstrap › bootstrap_ref_js_modal.asp
Bootstrap JS Modal Reference
The Modal plugin is a dialog box/popup window that is displayed on top of the current page.
Find elsewhere
🌐
Bootstrap
getbootstrap.com › docs › 4.5 › components › modal
Modal · Bootstrap v4.5
Once again, due to position: fixed, there are some caveats with using modals on mobile devices. See our browser support docs for details. Due to how HTML5 defines its semantics, the autofocus HTML attribute has no effect in Bootstrap modals.
🌐
MDBootstrap
mdbootstrap.com › standard › modal
Bootstrap Modal - free examples & tutorial
Responsive popup window with Bootstrap 5. Examples of with image, modal position i.e. center, z-index usage, modal fade animation, backdrop usage, modal size & more.
🌐
W3Schools
w3schools.com › bootstrap4 › bootstrap_modal.asp
Bootstrap 4 Modals
For a complete reference of all modal options, methods and events, go to our Bootstrap JS Modal Reference.
🌐
Tutorial Republic
tutorialrepublic.com › twitter-bootstrap-tutorial › bootstrap-modals.php
How to Create Modals with Bootstrap 5 - Tutorial Republic
Learn how to implement modal window, dialog box or popup functionality using the Bootstrap modal plugin with minimum effort without writing any JavaScript code.
🌐
Bootstrap
getbootstrap.com › docs › 5.3 › examples › modals
Modals · Bootstrap v5.3
This is a modal sheet, a variation of the modal that docs itself to the bottom of the viewport like the newer share sheets in iOS.
🌐
Bootstrap
getbootstrap.com › docs › 5.2 › components › modal
Modal · Bootstrap v5.2
Embedding YouTube videos in modals requires additional JavaScript not in Bootstrap to automatically stop playback and more. See this helpful Stack Overflow post for more information. Modals have three optional sizes, available via modifier classes to be placed on a .modal-dialog.
🌐
W3Schools
w3schools.in › bootstrap4 › modal
How to Create Modal with Bootstrap 4 - W3Schools
Often developers need to embed a dialog box to pop additional content into a webpage. This feature is provided by Bootstrap 4 through a modal. In this tutorial, you will learn about Modal and the various ways of its implementation.
🌐
Bootstrap
getbootstrap.com › docs › 5.1 › components › modal
Modal · Bootstrap v5.1
Clicking on the modal “backdrop” will automatically close the modal. Bootstrap only supports one modal window at a time.
Top answer
1 of 9
66

The modal plugin toggles your hidden content on demand, via data attributes or JavaScript. It also adds .modal-open to the to override default scrolling behavior and generates a .modal-backdrop to provide a click area for dismissing shown modals when clicking outside the modal. [source]

How to use via Vanilla JavaScript

Create a modal with a single line of JavaScript:

var myModal = new bootstrap.Modal(document.getElementById('myModal'), options)

source

A quick example:

var myModal = new bootstrap.Modal(document.getElementById("exampleModal"), {});
document.onreadystatechange = function () {
  myModal.show();
};
<!DOCTYPE html>
<html lang="en">
  <head>

    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, shrink-to-fit=no"
    />


    <link
      rel="stylesheet"
      href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/css/bootstrap.min.css"
      integrity="sha384-r4NyP46KrjDleawBgD5tp8Y7UzmLA05oM1iAEQ17CSuDqnUK2+k9luXQOfXJCJ4I"
      crossorigin="anonymous"
    />
    <title>Hello, world!</title>
  </head>
  <body>

    <div
      class="modal fade"
      id="exampleModal"
      tabindex="-1"
      role="dialog"
      aria-labelledby="exampleModalLabel"
      aria-hidden="true"
    >
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
            <button
              type="button"
              class="close"
              data-dismiss="modal"
              aria-label="Close"
            >
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            ...
          </div>
          <div class="modal-footer">
            <button
              type="button"
              class="btn btn-secondary"
              data-dismiss="modal"
            >
              Close
            </button>
            <button type="button" class="btn btn-primary">Save changes</button>
          </div>
        </div>
      </div>
    </div>

    <!-- JavaScript and dependencies -->
    <script
      src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
      integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
      crossorigin="anonymous"
    ></script>
    <script
      src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js"
      integrity="sha384-oesi62hOLfzrys4LxRF63OJCXdXDipiYWBnvTl9Y9/TRlw5xlKIEHpNyvvDShgf/"
      crossorigin="anonymous"
    ></script>

    <script src="./app.js"></script>
  </body>
</html>

As for your code, you didn't follow the right way to show/toggle a modal in Vanilla JavaScript. Why did you expect myModal.show() to happen while myModal is just a DOM element?

2 of 9
38
  1. Create a new instace of modal and then call show method(see usage points)
var myModal = new bootstrap.Modal(document.getElementById('exampleModal'))
myModal.show()

ref: https://v5.getbootstrap.com/docs/5.0/components/modal/#options

note: Bootstrap v5 no more uses jquery, instead it uses javascript. lots of changes are there in bootstrap v5, if you are working for a company and willing to use Bootstrap v5 then please go through all the changes.