Show modal on click anchor tag

Created at 20-Sep-2021 , By samar

Show modal on click anchor tag

In this tutorial, we will try to find the solution to "Show modal on click anchor tag" through programming.

You can show modal on click anchor tag using bootstrap in HTML page.
  • Show bootstrap modal on click anchor tag in HTML

    Anchor tag

    <a href="javascript:void(0)" data-toggle="modal" data-target="#myModal"> <i class="fa fa-plus" aria-hidden="true"></i> </a>

    Bootstrap modal

    <div class="modal" id="myModal">
       <div class="modal-dialog ">
           <div class="modal-content">
               <div class="modal-header">
                  <h4 class="modal-title">Modal title</h4>
                   <button type="button" class="close" data-dismiss="modal">&amp;times;</button>
              <div class="modal-body">
            <p>Modal body text goes here.</p>
               <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>

    You can display bootstrap modal using data attribute (data-toggle, data-target) in anchor tag. You have to use bootstrap CDN in your HTML page in which you want to use the bootstrap modal.

    <script src=""></script>
    <link rel="stylesheet" href="" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
    <script src=""></script>
  • How do I open modal pop on href onclick?

    Just change the button for <a href="#" id="myBtn">Open Modal</a> , your current script will assign the onclick method.

  • How do I add a modal to a click button?

    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 you show modal dialog?

    The Window. showModalDialog() created and displayed a modal dialog box containing a specified HTML document.

  • How can I open modal pop without click button?

    onload event handler, the OpenBootstrapPopup JavaScript function is called which first references the HTML DIV using jQuery and then calls the Bootstrap modal function which displays the Bootstrap Modal Popup.

  • Can we use Onclick in anchor tag?

    Using onclick Event: The onclick event attribute works when the user click on the button. When mouse clicked on the button then the button acts like a link and redirect page into the given location. Using button tag inside <a> tag: This method create a button inside anchor tag.

  • How do I open modal onclick event?

    Use any HTML element to open the modal. This is often a button or a link. Add the onclick attribute and point to the id of the modal (id01 in our example), using the document. getElementById() method and specify a unique ID that matches the "trigger" button (id01).

  • How to show bootstrap modal before form Submit?

    For this, you first change your input type="submit" to input type="button" and add data-toggle="modal" data-target="#confirm-submit" so that the modal gets triggered when you click on it:

  • How do I show modal popup after submitting?

    <form class="form-inline" onsubmit="openModal()" id="myForm">
      <button type="submit" class="btn btn-primary">Submit</button>
  • Is modal same as popup?

    Modals, like pop-ups, are components that pop up on a user's screen. The key difference, however, is that the user would have initiated the action as part of their journey. Modals are used for specific workflows such as adding users, deleting content, sharing content, adding content, and more.

  • What can I use instead of a modal?

    In almost all cases, there is no need to force users into specific actions. As a result, modal windows introduce unnecessary pain points for your users. Instead, you should aim to create modeless user interfaces. Modeless user interfaces allow users to change their mind at any point.

Back to code snippet queries related bootstrap

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.