Close Bootstrap Modal











up vote
341
down vote

favorite
38












I have a bootstrap modal dialog box that I want to show initially, then when the user clicks on the page, it disappears. I have the following:



$(function () {
$('#modal').modal(toggle)
});

<div class="modal" id='modal'>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Error:</h3>
</div>
<div class="modal-body">
<p>Please correct the following errors:</p>
</div>
</div>
</div>


The modal is displayed initially, but it does not close when clicked outside of the modal. Also, the content area is not greyed out.. How can I get the modal to display initially, then close after the user clicks outside the area? And how can I get the background to be grayed out as in the demo?










share|improve this question
























  • Are you initializing your modal with $("#yourModal").modal() or $('.modal').modal()?
    – merv
    May 11 '13 at 3:13












  • Added more context above. Thanks for any ideas @merv!
    – Nick B
    May 11 '13 at 3:18










  • yep...that showed the problem. @Tamil has your solution.
    – merv
    May 11 '13 at 3:22















up vote
341
down vote

favorite
38












I have a bootstrap modal dialog box that I want to show initially, then when the user clicks on the page, it disappears. I have the following:



$(function () {
$('#modal').modal(toggle)
});

<div class="modal" id='modal'>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Error:</h3>
</div>
<div class="modal-body">
<p>Please correct the following errors:</p>
</div>
</div>
</div>


The modal is displayed initially, but it does not close when clicked outside of the modal. Also, the content area is not greyed out.. How can I get the modal to display initially, then close after the user clicks outside the area? And how can I get the background to be grayed out as in the demo?










share|improve this question
























  • Are you initializing your modal with $("#yourModal").modal() or $('.modal').modal()?
    – merv
    May 11 '13 at 3:13












  • Added more context above. Thanks for any ideas @merv!
    – Nick B
    May 11 '13 at 3:18










  • yep...that showed the problem. @Tamil has your solution.
    – merv
    May 11 '13 at 3:22













up vote
341
down vote

favorite
38









up vote
341
down vote

favorite
38






38





I have a bootstrap modal dialog box that I want to show initially, then when the user clicks on the page, it disappears. I have the following:



$(function () {
$('#modal').modal(toggle)
});

<div class="modal" id='modal'>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Error:</h3>
</div>
<div class="modal-body">
<p>Please correct the following errors:</p>
</div>
</div>
</div>


The modal is displayed initially, but it does not close when clicked outside of the modal. Also, the content area is not greyed out.. How can I get the modal to display initially, then close after the user clicks outside the area? And how can I get the background to be grayed out as in the demo?










share|improve this question















I have a bootstrap modal dialog box that I want to show initially, then when the user clicks on the page, it disappears. I have the following:



$(function () {
$('#modal').modal(toggle)
});

<div class="modal" id='modal'>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Error:</h3>
</div>
<div class="modal-body">
<p>Please correct the following errors:</p>
</div>
</div>
</div>


The modal is displayed initially, but it does not close when clicked outside of the modal. Also, the content area is not greyed out.. How can I get the modal to display initially, then close after the user clicks outside the area? And how can I get the background to be grayed out as in the demo?







jquery twitter-bootstrap modal-dialog






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 3 '16 at 7:08









Arslan Ali

12.8k63454




12.8k63454










asked May 11 '13 at 2:49









Nick B

3,143104584




3,143104584












  • Are you initializing your modal with $("#yourModal").modal() or $('.modal').modal()?
    – merv
    May 11 '13 at 3:13












  • Added more context above. Thanks for any ideas @merv!
    – Nick B
    May 11 '13 at 3:18










  • yep...that showed the problem. @Tamil has your solution.
    – merv
    May 11 '13 at 3:22


















  • Are you initializing your modal with $("#yourModal").modal() or $('.modal').modal()?
    – merv
    May 11 '13 at 3:13












  • Added more context above. Thanks for any ideas @merv!
    – Nick B
    May 11 '13 at 3:18










  • yep...that showed the problem. @Tamil has your solution.
    – merv
    May 11 '13 at 3:22
















Are you initializing your modal with $("#yourModal").modal() or $('.modal').modal()?
– merv
May 11 '13 at 3:13






Are you initializing your modal with $("#yourModal").modal() or $('.modal').modal()?
– merv
May 11 '13 at 3:13














Added more context above. Thanks for any ideas @merv!
– Nick B
May 11 '13 at 3:18




Added more context above. Thanks for any ideas @merv!
– Nick B
May 11 '13 at 3:18












yep...that showed the problem. @Tamil has your solution.
– merv
May 11 '13 at 3:22




yep...that showed the problem. @Tamil has your solution.
– merv
May 11 '13 at 3:22












20 Answers
20






active

oldest

votes

















up vote
547
down vote



accepted










Put modal('toggle') instead of modal(toggle)



$(function () {
$('#modal').modal('toggle');
});





share|improve this answer

















  • 4




    Including the 'toggle' at all is superflous. Just make sure not to have a 'hide' class on the modal div. But yes, the typo was causing the issue. so +1
    – merv
    May 11 '13 at 3:21








  • 16




    no it does not work as intended, it hides the modal element but the background overlay element still exists, you should use the @Subodth solution.
    – Parik Tiwari
    Jul 30 '16 at 2:19










  • @Pierre, Parik is correct
    – usefulBee
    Aug 24 '16 at 18:21






  • 1




    @Pierre - consider removing your comment, .modal().hide() is not the same as .modal('hide'), you are going to confuse people.
    – Michael Peterson
    Feb 23 '17 at 15:33






  • 2




    Like Parik said, the correct answer is using modal('hide')
    – MidouCloud
    Apr 11 at 9:41


















up vote
331
down vote













to close bootstrap modal you can pass 'hide' as option to modal method as follow



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


Please take a look at working fiddle here



bootstrap also provide events that you can hook into modal functionality, like if you want to fire a event when the modal has finished being hidden from the user you can use hidden.bs.modal event you can read more about modal methods and events here in Documentation



If none of the above method work, give a id to your close button and trigger click on close button.






share|improve this answer



















  • 4




    $('#modal').modal('toggle'); better to hide modal shadow
    – hamzeh.hanandeh
    Feb 24 '16 at 9:00






  • 4




    @hamzeh.hanandeh, toggle keeps the overlay and is not a solution. You should always use either show or hide.
    – ryanpcmcquen
    Mar 22 '17 at 16:16


















up vote
57
down vote













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


or



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


should work.



But if nothing else works you can call the modal close button directly:



$("#modal .close").click()





share|improve this answer

















  • 8




    the one with hide() closes the modal but leaves the background blurred. $("#modal .close").click() does it perfectly. Thank you!
    – Shilpa
    Sep 16 '16 at 8:06








  • 5




    your last option worked for me. thanks.
    – Kumaresan Perumal
    Sep 19 '16 at 8:33






  • 4




    This is clearly documented already, here is no need to fake a click, that seems pretty janky. The correct answer is: $('#modal').modal('hide');
    – Michael Peterson
    Feb 23 '17 at 15:31










  • this -> $('#modal').modal().hide();
    – TARA
    Jun 6 '17 at 4:09










  • I have a model which does not close with $('#modal').modal('hide') however i can close it using $('#modal').modal('toggle') but that display a vertical scroll bar after closing. So for me $('#modal').hide() worked perfectly but i wanna know if would that create any problems ? And i am coding inside $('#modal .close').click() so i don't think i could use it to close modal.
    – Ahtisham
    Nov 21 '17 at 19:56




















up vote
26
down vote













this worked for me:



<span class="button" data-dismiss="modal" aria-label="Close">cancel</span>


use this link modal close






share|improve this answer






























    up vote
    16
    down vote













    $("#your-modal-id").modal('hide');


    Running this call via class ($(".my-modal")) won't work.






    share|improve this answer




























      up vote
      9
      down vote













      this one is pretty good and it also works in angular 2



      $("#modal .close").click()





      share|improve this answer





















      • Works for me instead of $('#modal').modal('toggle'); which has no effect.
        – TodStoychev
        Jul 14 '17 at 8:09


















      up vote
      7
      down vote













      My five cents on this one is that I don't want to have to target the bootstrap modal with an id and seeing as there should be only one modal at a time the following should be quite sufficient to remove the modal as toggle could be dangerous:



      $('.modal').removeClass('show');





      share|improve this answer

















      • 2




        The intentions are good, but this approach won't always work. Other page elements, including <body>, have classes added to them that would have to be reverted as well. The best answer is to use the 'hide' method.
        – JustinStolle
        Aug 21 '15 at 5:25




















      up vote
      7
      down vote













      In some circumstances typing error could be the culprit. For instance, make sure you have:



      data-dismiss="modal"


      and not



      data-dissmiss="modal"


      Notice the double "ss" in the second example that will cause the Close button that fail.






      share|improve this answer




























        up vote
        6
        down vote













        We can close the modal pop-up in the following ways:



        // We use data-dismiss property of modal-up in html to close the modal-up,such as

        <div class='modal-footer'><button type='button' class="btn btn-default" data-dismiss='modal'>Close</button></div>

        // We can close the modal pop-up through java script, such as

        <div class='modal fade pageModal' id='openModal' tabindex='-1' data-keyboard='false' data-backdrop='static'>

        $('#openModal').modal('hide'); //Using modal pop-up Id.
        $('.pageModal').modal('hide'); //Using class that is defined in modal html.





        share|improve this answer




























          up vote
          5
          down vote













             function Delete(){
          var id = $("#dgetid").val();
          debugger
          $.ajax({
          type: "POST",
          url: "Add_NewProduct.aspx/DeleteData",
          data: "{id:'" + id + "'}",
          datatype: "json",
          contentType: "application/json; charset=utf-8",
          success: function (result) {
          if (result.d == 1) {
          bindData();
          setTimeout(function(){ $('#DeleteModal').modal('hide');},1000);
          }
          }
          });
          };





          share|improve this answer























          • Hi - thanks for your answer. I've formatted this as code (which was fairly simple - just indent the first line a bit more). However I'd guess that only the $('#DeleteModal').modal('hide'); is relevant here?
            – Rup
            Jul 9 at 11:18




















          up vote
          4
          down vote













          $('.modal.in').modal('hide');



          use the above code to hide the backdrop of modal if you are using multiple modal pop in one page.






          share|improve this answer






























            up vote
            4
            down vote
















            <!DOCTYPE html>
            <html lang="en">
            <head>
            <title>Bootstrap Example</title>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
            <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
            <script>
            $(window).load(function(){
            $('#myModal').modal('show');
            });
            $(function () {
            $('#modal').modal('toggle');
            });
            </script>
            </head>
            <body>

            <div class="container">
            <h2>Modal Example</h2>
            <!-- Trigger the modal with a button -->
            <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

            <!-- Modal -->
            <div class="modal fade" id="myModal" role="dialog">
            <div class="modal-dialog">

            <!-- Modal content-->
            <div class="modal-content">
            <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Modal Header</h4>
            </div>
            <div class="modal-body">
            <p>Some text in the modal.</p>
            </div>
            <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
            </div>

            </div>
            </div>

            </div>

            </body>
            </html>








            share|improve this answer























            • Error: "message": "Uncaught TypeError: $(...).modal is not a function"
              – Ivan Burlutskiy
              Dec 9 '17 at 21:15










            • you got this error?
              – Ganesh Putta
              Dec 11 '17 at 4:41










            • Yes. I have the error if "Run code snippet" in Chrome (Linux Mint). But it works in Firefox.
              – Ivan Burlutskiy
              Dec 11 '17 at 6:54






            • 1




              @Ivan Burlutskiy, Thank u for informing me, These is a issue with jquery include, so i fixed it. now it works fine in all browsers.
              – Ganesh Putta
              Dec 11 '17 at 7:10


















            up vote
            3
            down vote













            Using modal.hide would only hide the modal. If you are using overlay underneath the modal, it would still be there. use click call to actually close the modal and remove the overlay.



            $("#modalID .close").click()





            share|improve this answer





















            • this is correct one
              – Veshraj Joshi
              Mar 6 '17 at 4:23


















            up vote
            3
            down vote













            you can use;



            $('#' + $('.modal.show').attr('id')).modal('hide');





            share|improve this answer




























              up vote
              2
              down vote













              Another way of doing this is that first you remove the class modal-open, which closes the modal. Then you remove the class modal-backdrop that removes the grayish cover of the modal.



              Following code can be used:



              $('body').removeClass('modal-open')
              $('.modal-backdrop').remove()





              share|improve this answer























              • Please try to avoid just dumping code as an answer and try to explain what it does and why. Your code might not be obvious for people who do not have the relevant coding experience. Please edit your answer to include clarification, context and try to mention any limitations, assumptions or simplifications in your answer.
                – Frits
                May 31 '17 at 6:24










              • OK, so basically what this does is removes the class modal-open, which closes the modal. then removes the class modal-backdrop that removes the grayish cover of the modal
                – Orozcorp
                May 31 '17 at 21:17


















              up vote
              2
              down vote













              In my case, main page from where bootstrap modal was triggered started to not responding after using $("#modal").modal('toggle'); way, but started responding in the following way:



              $("#submitBtn").on("click",function(){
              $("#submitBtn").attr("data-dismiss","modal");
              });





              share|improve this answer























              • Genius! Best working solution +1
                – Zohab Ali
                Jun 4 at 9:31


















              up vote
              1
              down vote













              Besides, you can "click" on a 'x', that closes dialog.
              E.g.:



              $(".ui-dialog-titlebar-close").click();






              share|improve this answer




























                up vote
                1
                down vote













                This code worked perfectly for me to close a modal (i'm using bootstrap 3.3)



                $('#myModal').removeClass('in')





                share|improve this answer




























                  up vote
                  1
                  down vote














                  I closed modal Programmatically with this trick




                  Add a button in modal with data-dismiss="modal" and hide the button with display: none. Here is how it will look like



                  <div class="modal fade" id="addNewPaymentMethod" role="dialog">
                  <div class="modal-dialog">
                  .
                  .
                  .
                  <button type="button" id="close-modal" data-dismiss="modal" style="display: none">Close</button>
                  </div>
                  </div>


                  Now when you want to close modal Programmatically just trigger a click event on that button, which is not visible to user



                  In Javascript you can trigger click on that button like this:



                  document.getElementById('close-modal').click();





                  share|improve this answer




























                    up vote
                    0
                    down vote













                    This works well



                    $(function () {
                    $('#modal').modal('toggle');
                    });


                    However, when you have multiple modals stacking on top one another it is not effective, so instead , this works



                    data-dismiss="modal"





                    share|improve this answer





















                      Your Answer






                      StackExchange.ifUsing("editor", function () {
                      StackExchange.using("externalEditor", function () {
                      StackExchange.using("snippets", function () {
                      StackExchange.snippets.init();
                      });
                      });
                      }, "code-snippets");

                      StackExchange.ready(function() {
                      var channelOptions = {
                      tags: "".split(" "),
                      id: "1"
                      };
                      initTagRenderer("".split(" "), "".split(" "), channelOptions);

                      StackExchange.using("externalEditor", function() {
                      // Have to fire editor after snippets, if snippets enabled
                      if (StackExchange.settings.snippets.snippetsEnabled) {
                      StackExchange.using("snippets", function() {
                      createEditor();
                      });
                      }
                      else {
                      createEditor();
                      }
                      });

                      function createEditor() {
                      StackExchange.prepareEditor({
                      heartbeatType: 'answer',
                      convertImagesToLinks: true,
                      noModals: true,
                      showLowRepImageUploadWarning: true,
                      reputationToPostImages: 10,
                      bindNavPrevention: true,
                      postfix: "",
                      imageUploader: {
                      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                      allowUrls: true
                      },
                      onDemand: true,
                      discardSelector: ".discard-answer"
                      ,immediatelyShowMarkdownHelp:true
                      });


                      }
                      });














                      draft saved

                      draft discarded


















                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16493280%2fclose-bootstrap-modal%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown

























                      20 Answers
                      20






                      active

                      oldest

                      votes








                      20 Answers
                      20






                      active

                      oldest

                      votes









                      active

                      oldest

                      votes






                      active

                      oldest

                      votes








                      up vote
                      547
                      down vote



                      accepted










                      Put modal('toggle') instead of modal(toggle)



                      $(function () {
                      $('#modal').modal('toggle');
                      });





                      share|improve this answer

















                      • 4




                        Including the 'toggle' at all is superflous. Just make sure not to have a 'hide' class on the modal div. But yes, the typo was causing the issue. so +1
                        – merv
                        May 11 '13 at 3:21








                      • 16




                        no it does not work as intended, it hides the modal element but the background overlay element still exists, you should use the @Subodth solution.
                        – Parik Tiwari
                        Jul 30 '16 at 2:19










                      • @Pierre, Parik is correct
                        – usefulBee
                        Aug 24 '16 at 18:21






                      • 1




                        @Pierre - consider removing your comment, .modal().hide() is not the same as .modal('hide'), you are going to confuse people.
                        – Michael Peterson
                        Feb 23 '17 at 15:33






                      • 2




                        Like Parik said, the correct answer is using modal('hide')
                        – MidouCloud
                        Apr 11 at 9:41















                      up vote
                      547
                      down vote



                      accepted










                      Put modal('toggle') instead of modal(toggle)



                      $(function () {
                      $('#modal').modal('toggle');
                      });





                      share|improve this answer

















                      • 4




                        Including the 'toggle' at all is superflous. Just make sure not to have a 'hide' class on the modal div. But yes, the typo was causing the issue. so +1
                        – merv
                        May 11 '13 at 3:21








                      • 16




                        no it does not work as intended, it hides the modal element but the background overlay element still exists, you should use the @Subodth solution.
                        – Parik Tiwari
                        Jul 30 '16 at 2:19










                      • @Pierre, Parik is correct
                        – usefulBee
                        Aug 24 '16 at 18:21






                      • 1




                        @Pierre - consider removing your comment, .modal().hide() is not the same as .modal('hide'), you are going to confuse people.
                        – Michael Peterson
                        Feb 23 '17 at 15:33






                      • 2




                        Like Parik said, the correct answer is using modal('hide')
                        – MidouCloud
                        Apr 11 at 9:41













                      up vote
                      547
                      down vote



                      accepted







                      up vote
                      547
                      down vote



                      accepted






                      Put modal('toggle') instead of modal(toggle)



                      $(function () {
                      $('#modal').modal('toggle');
                      });





                      share|improve this answer












                      Put modal('toggle') instead of modal(toggle)



                      $(function () {
                      $('#modal').modal('toggle');
                      });






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered May 11 '13 at 3:19









                      Tamil Selvan C

                      13.9k93356




                      13.9k93356








                      • 4




                        Including the 'toggle' at all is superflous. Just make sure not to have a 'hide' class on the modal div. But yes, the typo was causing the issue. so +1
                        – merv
                        May 11 '13 at 3:21








                      • 16




                        no it does not work as intended, it hides the modal element but the background overlay element still exists, you should use the @Subodth solution.
                        – Parik Tiwari
                        Jul 30 '16 at 2:19










                      • @Pierre, Parik is correct
                        – usefulBee
                        Aug 24 '16 at 18:21






                      • 1




                        @Pierre - consider removing your comment, .modal().hide() is not the same as .modal('hide'), you are going to confuse people.
                        – Michael Peterson
                        Feb 23 '17 at 15:33






                      • 2




                        Like Parik said, the correct answer is using modal('hide')
                        – MidouCloud
                        Apr 11 at 9:41














                      • 4




                        Including the 'toggle' at all is superflous. Just make sure not to have a 'hide' class on the modal div. But yes, the typo was causing the issue. so +1
                        – merv
                        May 11 '13 at 3:21








                      • 16




                        no it does not work as intended, it hides the modal element but the background overlay element still exists, you should use the @Subodth solution.
                        – Parik Tiwari
                        Jul 30 '16 at 2:19










                      • @Pierre, Parik is correct
                        – usefulBee
                        Aug 24 '16 at 18:21






                      • 1




                        @Pierre - consider removing your comment, .modal().hide() is not the same as .modal('hide'), you are going to confuse people.
                        – Michael Peterson
                        Feb 23 '17 at 15:33






                      • 2




                        Like Parik said, the correct answer is using modal('hide')
                        – MidouCloud
                        Apr 11 at 9:41








                      4




                      4




                      Including the 'toggle' at all is superflous. Just make sure not to have a 'hide' class on the modal div. But yes, the typo was causing the issue. so +1
                      – merv
                      May 11 '13 at 3:21






                      Including the 'toggle' at all is superflous. Just make sure not to have a 'hide' class on the modal div. But yes, the typo was causing the issue. so +1
                      – merv
                      May 11 '13 at 3:21






                      16




                      16




                      no it does not work as intended, it hides the modal element but the background overlay element still exists, you should use the @Subodth solution.
                      – Parik Tiwari
                      Jul 30 '16 at 2:19




                      no it does not work as intended, it hides the modal element but the background overlay element still exists, you should use the @Subodth solution.
                      – Parik Tiwari
                      Jul 30 '16 at 2:19












                      @Pierre, Parik is correct
                      – usefulBee
                      Aug 24 '16 at 18:21




                      @Pierre, Parik is correct
                      – usefulBee
                      Aug 24 '16 at 18:21




                      1




                      1




                      @Pierre - consider removing your comment, .modal().hide() is not the same as .modal('hide'), you are going to confuse people.
                      – Michael Peterson
                      Feb 23 '17 at 15:33




                      @Pierre - consider removing your comment, .modal().hide() is not the same as .modal('hide'), you are going to confuse people.
                      – Michael Peterson
                      Feb 23 '17 at 15:33




                      2




                      2




                      Like Parik said, the correct answer is using modal('hide')
                      – MidouCloud
                      Apr 11 at 9:41




                      Like Parik said, the correct answer is using modal('hide')
                      – MidouCloud
                      Apr 11 at 9:41












                      up vote
                      331
                      down vote













                      to close bootstrap modal you can pass 'hide' as option to modal method as follow



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


                      Please take a look at working fiddle here



                      bootstrap also provide events that you can hook into modal functionality, like if you want to fire a event when the modal has finished being hidden from the user you can use hidden.bs.modal event you can read more about modal methods and events here in Documentation



                      If none of the above method work, give a id to your close button and trigger click on close button.






                      share|improve this answer



















                      • 4




                        $('#modal').modal('toggle'); better to hide modal shadow
                        – hamzeh.hanandeh
                        Feb 24 '16 at 9:00






                      • 4




                        @hamzeh.hanandeh, toggle keeps the overlay and is not a solution. You should always use either show or hide.
                        – ryanpcmcquen
                        Mar 22 '17 at 16:16















                      up vote
                      331
                      down vote













                      to close bootstrap modal you can pass 'hide' as option to modal method as follow



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


                      Please take a look at working fiddle here



                      bootstrap also provide events that you can hook into modal functionality, like if you want to fire a event when the modal has finished being hidden from the user you can use hidden.bs.modal event you can read more about modal methods and events here in Documentation



                      If none of the above method work, give a id to your close button and trigger click on close button.






                      share|improve this answer



















                      • 4




                        $('#modal').modal('toggle'); better to hide modal shadow
                        – hamzeh.hanandeh
                        Feb 24 '16 at 9:00






                      • 4




                        @hamzeh.hanandeh, toggle keeps the overlay and is not a solution. You should always use either show or hide.
                        – ryanpcmcquen
                        Mar 22 '17 at 16:16













                      up vote
                      331
                      down vote










                      up vote
                      331
                      down vote









                      to close bootstrap modal you can pass 'hide' as option to modal method as follow



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


                      Please take a look at working fiddle here



                      bootstrap also provide events that you can hook into modal functionality, like if you want to fire a event when the modal has finished being hidden from the user you can use hidden.bs.modal event you can read more about modal methods and events here in Documentation



                      If none of the above method work, give a id to your close button and trigger click on close button.






                      share|improve this answer














                      to close bootstrap modal you can pass 'hide' as option to modal method as follow



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


                      Please take a look at working fiddle here



                      bootstrap also provide events that you can hook into modal functionality, like if you want to fire a event when the modal has finished being hidden from the user you can use hidden.bs.modal event you can read more about modal methods and events here in Documentation



                      If none of the above method work, give a id to your close button and trigger click on close button.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Oct 25 '15 at 6:01

























                      answered Nov 25 '13 at 11:16









                      Subodh Ghulaxe

                      13.6k117092




                      13.6k117092








                      • 4




                        $('#modal').modal('toggle'); better to hide modal shadow
                        – hamzeh.hanandeh
                        Feb 24 '16 at 9:00






                      • 4




                        @hamzeh.hanandeh, toggle keeps the overlay and is not a solution. You should always use either show or hide.
                        – ryanpcmcquen
                        Mar 22 '17 at 16:16














                      • 4




                        $('#modal').modal('toggle'); better to hide modal shadow
                        – hamzeh.hanandeh
                        Feb 24 '16 at 9:00






                      • 4




                        @hamzeh.hanandeh, toggle keeps the overlay and is not a solution. You should always use either show or hide.
                        – ryanpcmcquen
                        Mar 22 '17 at 16:16








                      4




                      4




                      $('#modal').modal('toggle'); better to hide modal shadow
                      – hamzeh.hanandeh
                      Feb 24 '16 at 9:00




                      $('#modal').modal('toggle'); better to hide modal shadow
                      – hamzeh.hanandeh
                      Feb 24 '16 at 9:00




                      4




                      4




                      @hamzeh.hanandeh, toggle keeps the overlay and is not a solution. You should always use either show or hide.
                      – ryanpcmcquen
                      Mar 22 '17 at 16:16




                      @hamzeh.hanandeh, toggle keeps the overlay and is not a solution. You should always use either show or hide.
                      – ryanpcmcquen
                      Mar 22 '17 at 16:16










                      up vote
                      57
                      down vote













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


                      or



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


                      should work.



                      But if nothing else works you can call the modal close button directly:



                      $("#modal .close").click()





                      share|improve this answer

















                      • 8




                        the one with hide() closes the modal but leaves the background blurred. $("#modal .close").click() does it perfectly. Thank you!
                        – Shilpa
                        Sep 16 '16 at 8:06








                      • 5




                        your last option worked for me. thanks.
                        – Kumaresan Perumal
                        Sep 19 '16 at 8:33






                      • 4




                        This is clearly documented already, here is no need to fake a click, that seems pretty janky. The correct answer is: $('#modal').modal('hide');
                        – Michael Peterson
                        Feb 23 '17 at 15:31










                      • this -> $('#modal').modal().hide();
                        – TARA
                        Jun 6 '17 at 4:09










                      • I have a model which does not close with $('#modal').modal('hide') however i can close it using $('#modal').modal('toggle') but that display a vertical scroll bar after closing. So for me $('#modal').hide() worked perfectly but i wanna know if would that create any problems ? And i am coding inside $('#modal .close').click() so i don't think i could use it to close modal.
                        – Ahtisham
                        Nov 21 '17 at 19:56

















                      up vote
                      57
                      down vote













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


                      or



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


                      should work.



                      But if nothing else works you can call the modal close button directly:



                      $("#modal .close").click()





                      share|improve this answer

















                      • 8




                        the one with hide() closes the modal but leaves the background blurred. $("#modal .close").click() does it perfectly. Thank you!
                        – Shilpa
                        Sep 16 '16 at 8:06








                      • 5




                        your last option worked for me. thanks.
                        – Kumaresan Perumal
                        Sep 19 '16 at 8:33






                      • 4




                        This is clearly documented already, here is no need to fake a click, that seems pretty janky. The correct answer is: $('#modal').modal('hide');
                        – Michael Peterson
                        Feb 23 '17 at 15:31










                      • this -> $('#modal').modal().hide();
                        – TARA
                        Jun 6 '17 at 4:09










                      • I have a model which does not close with $('#modal').modal('hide') however i can close it using $('#modal').modal('toggle') but that display a vertical scroll bar after closing. So for me $('#modal').hide() worked perfectly but i wanna know if would that create any problems ? And i am coding inside $('#modal .close').click() so i don't think i could use it to close modal.
                        – Ahtisham
                        Nov 21 '17 at 19:56















                      up vote
                      57
                      down vote










                      up vote
                      57
                      down vote









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


                      or



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


                      should work.



                      But if nothing else works you can call the modal close button directly:



                      $("#modal .close").click()





                      share|improve this answer












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


                      or



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


                      should work.



                      But if nothing else works you can call the modal close button directly:



                      $("#modal .close").click()






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jun 9 '16 at 12:04









                      Robert Benyi

                      88989




                      88989








                      • 8




                        the one with hide() closes the modal but leaves the background blurred. $("#modal .close").click() does it perfectly. Thank you!
                        – Shilpa
                        Sep 16 '16 at 8:06








                      • 5




                        your last option worked for me. thanks.
                        – Kumaresan Perumal
                        Sep 19 '16 at 8:33






                      • 4




                        This is clearly documented already, here is no need to fake a click, that seems pretty janky. The correct answer is: $('#modal').modal('hide');
                        – Michael Peterson
                        Feb 23 '17 at 15:31










                      • this -> $('#modal').modal().hide();
                        – TARA
                        Jun 6 '17 at 4:09










                      • I have a model which does not close with $('#modal').modal('hide') however i can close it using $('#modal').modal('toggle') but that display a vertical scroll bar after closing. So for me $('#modal').hide() worked perfectly but i wanna know if would that create any problems ? And i am coding inside $('#modal .close').click() so i don't think i could use it to close modal.
                        – Ahtisham
                        Nov 21 '17 at 19:56
















                      • 8




                        the one with hide() closes the modal but leaves the background blurred. $("#modal .close").click() does it perfectly. Thank you!
                        – Shilpa
                        Sep 16 '16 at 8:06








                      • 5




                        your last option worked for me. thanks.
                        – Kumaresan Perumal
                        Sep 19 '16 at 8:33






                      • 4




                        This is clearly documented already, here is no need to fake a click, that seems pretty janky. The correct answer is: $('#modal').modal('hide');
                        – Michael Peterson
                        Feb 23 '17 at 15:31










                      • this -> $('#modal').modal().hide();
                        – TARA
                        Jun 6 '17 at 4:09










                      • I have a model which does not close with $('#modal').modal('hide') however i can close it using $('#modal').modal('toggle') but that display a vertical scroll bar after closing. So for me $('#modal').hide() worked perfectly but i wanna know if would that create any problems ? And i am coding inside $('#modal .close').click() so i don't think i could use it to close modal.
                        – Ahtisham
                        Nov 21 '17 at 19:56










                      8




                      8




                      the one with hide() closes the modal but leaves the background blurred. $("#modal .close").click() does it perfectly. Thank you!
                      – Shilpa
                      Sep 16 '16 at 8:06






                      the one with hide() closes the modal but leaves the background blurred. $("#modal .close").click() does it perfectly. Thank you!
                      – Shilpa
                      Sep 16 '16 at 8:06






                      5




                      5




                      your last option worked for me. thanks.
                      – Kumaresan Perumal
                      Sep 19 '16 at 8:33




                      your last option worked for me. thanks.
                      – Kumaresan Perumal
                      Sep 19 '16 at 8:33




                      4




                      4




                      This is clearly documented already, here is no need to fake a click, that seems pretty janky. The correct answer is: $('#modal').modal('hide');
                      – Michael Peterson
                      Feb 23 '17 at 15:31




                      This is clearly documented already, here is no need to fake a click, that seems pretty janky. The correct answer is: $('#modal').modal('hide');
                      – Michael Peterson
                      Feb 23 '17 at 15:31












                      this -> $('#modal').modal().hide();
                      – TARA
                      Jun 6 '17 at 4:09




                      this -> $('#modal').modal().hide();
                      – TARA
                      Jun 6 '17 at 4:09












                      I have a model which does not close with $('#modal').modal('hide') however i can close it using $('#modal').modal('toggle') but that display a vertical scroll bar after closing. So for me $('#modal').hide() worked perfectly but i wanna know if would that create any problems ? And i am coding inside $('#modal .close').click() so i don't think i could use it to close modal.
                      – Ahtisham
                      Nov 21 '17 at 19:56






                      I have a model which does not close with $('#modal').modal('hide') however i can close it using $('#modal').modal('toggle') but that display a vertical scroll bar after closing. So for me $('#modal').hide() worked perfectly but i wanna know if would that create any problems ? And i am coding inside $('#modal .close').click() so i don't think i could use it to close modal.
                      – Ahtisham
                      Nov 21 '17 at 19:56












                      up vote
                      26
                      down vote













                      this worked for me:



                      <span class="button" data-dismiss="modal" aria-label="Close">cancel</span>


                      use this link modal close






                      share|improve this answer



























                        up vote
                        26
                        down vote













                        this worked for me:



                        <span class="button" data-dismiss="modal" aria-label="Close">cancel</span>


                        use this link modal close






                        share|improve this answer

























                          up vote
                          26
                          down vote










                          up vote
                          26
                          down vote









                          this worked for me:



                          <span class="button" data-dismiss="modal" aria-label="Close">cancel</span>


                          use this link modal close






                          share|improve this answer














                          this worked for me:



                          <span class="button" data-dismiss="modal" aria-label="Close">cancel</span>


                          use this link modal close







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Oct 11 at 13:56









                          AmmarCSE

                          25.5k42036




                          25.5k42036










                          answered Dec 12 '15 at 12:15









                          santhosh

                          1,0751428




                          1,0751428






















                              up vote
                              16
                              down vote













                              $("#your-modal-id").modal('hide');


                              Running this call via class ($(".my-modal")) won't work.






                              share|improve this answer

























                                up vote
                                16
                                down vote













                                $("#your-modal-id").modal('hide');


                                Running this call via class ($(".my-modal")) won't work.






                                share|improve this answer























                                  up vote
                                  16
                                  down vote










                                  up vote
                                  16
                                  down vote









                                  $("#your-modal-id").modal('hide');


                                  Running this call via class ($(".my-modal")) won't work.






                                  share|improve this answer












                                  $("#your-modal-id").modal('hide');


                                  Running this call via class ($(".my-modal")) won't work.







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Dec 5 '16 at 10:22









                                  Yishai Landau

                                  542312




                                  542312






















                                      up vote
                                      9
                                      down vote













                                      this one is pretty good and it also works in angular 2



                                      $("#modal .close").click()





                                      share|improve this answer





















                                      • Works for me instead of $('#modal').modal('toggle'); which has no effect.
                                        – TodStoychev
                                        Jul 14 '17 at 8:09















                                      up vote
                                      9
                                      down vote













                                      this one is pretty good and it also works in angular 2



                                      $("#modal .close").click()





                                      share|improve this answer





















                                      • Works for me instead of $('#modal').modal('toggle'); which has no effect.
                                        – TodStoychev
                                        Jul 14 '17 at 8:09













                                      up vote
                                      9
                                      down vote










                                      up vote
                                      9
                                      down vote









                                      this one is pretty good and it also works in angular 2



                                      $("#modal .close").click()





                                      share|improve this answer












                                      this one is pretty good and it also works in angular 2



                                      $("#modal .close").click()






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Mar 1 '17 at 5:58









                                      user3869304

                                      2021311




                                      2021311












                                      • Works for me instead of $('#modal').modal('toggle'); which has no effect.
                                        – TodStoychev
                                        Jul 14 '17 at 8:09


















                                      • Works for me instead of $('#modal').modal('toggle'); which has no effect.
                                        – TodStoychev
                                        Jul 14 '17 at 8:09
















                                      Works for me instead of $('#modal').modal('toggle'); which has no effect.
                                      – TodStoychev
                                      Jul 14 '17 at 8:09




                                      Works for me instead of $('#modal').modal('toggle'); which has no effect.
                                      – TodStoychev
                                      Jul 14 '17 at 8:09










                                      up vote
                                      7
                                      down vote













                                      My five cents on this one is that I don't want to have to target the bootstrap modal with an id and seeing as there should be only one modal at a time the following should be quite sufficient to remove the modal as toggle could be dangerous:



                                      $('.modal').removeClass('show');





                                      share|improve this answer

















                                      • 2




                                        The intentions are good, but this approach won't always work. Other page elements, including <body>, have classes added to them that would have to be reverted as well. The best answer is to use the 'hide' method.
                                        – JustinStolle
                                        Aug 21 '15 at 5:25

















                                      up vote
                                      7
                                      down vote













                                      My five cents on this one is that I don't want to have to target the bootstrap modal with an id and seeing as there should be only one modal at a time the following should be quite sufficient to remove the modal as toggle could be dangerous:



                                      $('.modal').removeClass('show');





                                      share|improve this answer

















                                      • 2




                                        The intentions are good, but this approach won't always work. Other page elements, including <body>, have classes added to them that would have to be reverted as well. The best answer is to use the 'hide' method.
                                        – JustinStolle
                                        Aug 21 '15 at 5:25















                                      up vote
                                      7
                                      down vote










                                      up vote
                                      7
                                      down vote









                                      My five cents on this one is that I don't want to have to target the bootstrap modal with an id and seeing as there should be only one modal at a time the following should be quite sufficient to remove the modal as toggle could be dangerous:



                                      $('.modal').removeClass('show');





                                      share|improve this answer












                                      My five cents on this one is that I don't want to have to target the bootstrap modal with an id and seeing as there should be only one modal at a time the following should be quite sufficient to remove the modal as toggle could be dangerous:



                                      $('.modal').removeClass('show');






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Aug 11 '15 at 9:26









                                      Andre Van Zuydam

                                      34245




                                      34245








                                      • 2




                                        The intentions are good, but this approach won't always work. Other page elements, including <body>, have classes added to them that would have to be reverted as well. The best answer is to use the 'hide' method.
                                        – JustinStolle
                                        Aug 21 '15 at 5:25
















                                      • 2




                                        The intentions are good, but this approach won't always work. Other page elements, including <body>, have classes added to them that would have to be reverted as well. The best answer is to use the 'hide' method.
                                        – JustinStolle
                                        Aug 21 '15 at 5:25










                                      2




                                      2




                                      The intentions are good, but this approach won't always work. Other page elements, including <body>, have classes added to them that would have to be reverted as well. The best answer is to use the 'hide' method.
                                      – JustinStolle
                                      Aug 21 '15 at 5:25






                                      The intentions are good, but this approach won't always work. Other page elements, including <body>, have classes added to them that would have to be reverted as well. The best answer is to use the 'hide' method.
                                      – JustinStolle
                                      Aug 21 '15 at 5:25












                                      up vote
                                      7
                                      down vote













                                      In some circumstances typing error could be the culprit. For instance, make sure you have:



                                      data-dismiss="modal"


                                      and not



                                      data-dissmiss="modal"


                                      Notice the double "ss" in the second example that will cause the Close button that fail.






                                      share|improve this answer

























                                        up vote
                                        7
                                        down vote













                                        In some circumstances typing error could be the culprit. For instance, make sure you have:



                                        data-dismiss="modal"


                                        and not



                                        data-dissmiss="modal"


                                        Notice the double "ss" in the second example that will cause the Close button that fail.






                                        share|improve this answer























                                          up vote
                                          7
                                          down vote










                                          up vote
                                          7
                                          down vote









                                          In some circumstances typing error could be the culprit. For instance, make sure you have:



                                          data-dismiss="modal"


                                          and not



                                          data-dissmiss="modal"


                                          Notice the double "ss" in the second example that will cause the Close button that fail.






                                          share|improve this answer












                                          In some circumstances typing error could be the culprit. For instance, make sure you have:



                                          data-dismiss="modal"


                                          and not



                                          data-dissmiss="modal"


                                          Notice the double "ss" in the second example that will cause the Close button that fail.







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Aug 13 '16 at 9:48









                                          zinczinc

                                          47058




                                          47058






















                                              up vote
                                              6
                                              down vote













                                              We can close the modal pop-up in the following ways:



                                              // We use data-dismiss property of modal-up in html to close the modal-up,such as

                                              <div class='modal-footer'><button type='button' class="btn btn-default" data-dismiss='modal'>Close</button></div>

                                              // We can close the modal pop-up through java script, such as

                                              <div class='modal fade pageModal' id='openModal' tabindex='-1' data-keyboard='false' data-backdrop='static'>

                                              $('#openModal').modal('hide'); //Using modal pop-up Id.
                                              $('.pageModal').modal('hide'); //Using class that is defined in modal html.





                                              share|improve this answer

























                                                up vote
                                                6
                                                down vote













                                                We can close the modal pop-up in the following ways:



                                                // We use data-dismiss property of modal-up in html to close the modal-up,such as

                                                <div class='modal-footer'><button type='button' class="btn btn-default" data-dismiss='modal'>Close</button></div>

                                                // We can close the modal pop-up through java script, such as

                                                <div class='modal fade pageModal' id='openModal' tabindex='-1' data-keyboard='false' data-backdrop='static'>

                                                $('#openModal').modal('hide'); //Using modal pop-up Id.
                                                $('.pageModal').modal('hide'); //Using class that is defined in modal html.





                                                share|improve this answer























                                                  up vote
                                                  6
                                                  down vote










                                                  up vote
                                                  6
                                                  down vote









                                                  We can close the modal pop-up in the following ways:



                                                  // We use data-dismiss property of modal-up in html to close the modal-up,such as

                                                  <div class='modal-footer'><button type='button' class="btn btn-default" data-dismiss='modal'>Close</button></div>

                                                  // We can close the modal pop-up through java script, such as

                                                  <div class='modal fade pageModal' id='openModal' tabindex='-1' data-keyboard='false' data-backdrop='static'>

                                                  $('#openModal').modal('hide'); //Using modal pop-up Id.
                                                  $('.pageModal').modal('hide'); //Using class that is defined in modal html.





                                                  share|improve this answer












                                                  We can close the modal pop-up in the following ways:



                                                  // We use data-dismiss property of modal-up in html to close the modal-up,such as

                                                  <div class='modal-footer'><button type='button' class="btn btn-default" data-dismiss='modal'>Close</button></div>

                                                  // We can close the modal pop-up through java script, such as

                                                  <div class='modal fade pageModal' id='openModal' tabindex='-1' data-keyboard='false' data-backdrop='static'>

                                                  $('#openModal').modal('hide'); //Using modal pop-up Id.
                                                  $('.pageModal').modal('hide'); //Using class that is defined in modal html.






                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Jun 5 '17 at 8:19









                                                  Sheo Dayal Singh

                                                  54355




                                                  54355






















                                                      up vote
                                                      5
                                                      down vote













                                                         function Delete(){
                                                      var id = $("#dgetid").val();
                                                      debugger
                                                      $.ajax({
                                                      type: "POST",
                                                      url: "Add_NewProduct.aspx/DeleteData",
                                                      data: "{id:'" + id + "'}",
                                                      datatype: "json",
                                                      contentType: "application/json; charset=utf-8",
                                                      success: function (result) {
                                                      if (result.d == 1) {
                                                      bindData();
                                                      setTimeout(function(){ $('#DeleteModal').modal('hide');},1000);
                                                      }
                                                      }
                                                      });
                                                      };





                                                      share|improve this answer























                                                      • Hi - thanks for your answer. I've formatted this as code (which was fairly simple - just indent the first line a bit more). However I'd guess that only the $('#DeleteModal').modal('hide'); is relevant here?
                                                        – Rup
                                                        Jul 9 at 11:18

















                                                      up vote
                                                      5
                                                      down vote













                                                         function Delete(){
                                                      var id = $("#dgetid").val();
                                                      debugger
                                                      $.ajax({
                                                      type: "POST",
                                                      url: "Add_NewProduct.aspx/DeleteData",
                                                      data: "{id:'" + id + "'}",
                                                      datatype: "json",
                                                      contentType: "application/json; charset=utf-8",
                                                      success: function (result) {
                                                      if (result.d == 1) {
                                                      bindData();
                                                      setTimeout(function(){ $('#DeleteModal').modal('hide');},1000);
                                                      }
                                                      }
                                                      });
                                                      };





                                                      share|improve this answer























                                                      • Hi - thanks for your answer. I've formatted this as code (which was fairly simple - just indent the first line a bit more). However I'd guess that only the $('#DeleteModal').modal('hide'); is relevant here?
                                                        – Rup
                                                        Jul 9 at 11:18















                                                      up vote
                                                      5
                                                      down vote










                                                      up vote
                                                      5
                                                      down vote









                                                         function Delete(){
                                                      var id = $("#dgetid").val();
                                                      debugger
                                                      $.ajax({
                                                      type: "POST",
                                                      url: "Add_NewProduct.aspx/DeleteData",
                                                      data: "{id:'" + id + "'}",
                                                      datatype: "json",
                                                      contentType: "application/json; charset=utf-8",
                                                      success: function (result) {
                                                      if (result.d == 1) {
                                                      bindData();
                                                      setTimeout(function(){ $('#DeleteModal').modal('hide');},1000);
                                                      }
                                                      }
                                                      });
                                                      };





                                                      share|improve this answer














                                                         function Delete(){
                                                      var id = $("#dgetid").val();
                                                      debugger
                                                      $.ajax({
                                                      type: "POST",
                                                      url: "Add_NewProduct.aspx/DeleteData",
                                                      data: "{id:'" + id + "'}",
                                                      datatype: "json",
                                                      contentType: "application/json; charset=utf-8",
                                                      success: function (result) {
                                                      if (result.d == 1) {
                                                      bindData();
                                                      setTimeout(function(){ $('#DeleteModal').modal('hide');},1000);
                                                      }
                                                      }
                                                      });
                                                      };






                                                      share|improve this answer














                                                      share|improve this answer



                                                      share|improve this answer








                                                      edited Jul 9 at 11:18









                                                      Rup

                                                      26.9k76385




                                                      26.9k76385










                                                      answered Jul 9 at 11:10









                                                      Sheladiya Ajay

                                                      5113




                                                      5113












                                                      • Hi - thanks for your answer. I've formatted this as code (which was fairly simple - just indent the first line a bit more). However I'd guess that only the $('#DeleteModal').modal('hide'); is relevant here?
                                                        – Rup
                                                        Jul 9 at 11:18




















                                                      • Hi - thanks for your answer. I've formatted this as code (which was fairly simple - just indent the first line a bit more). However I'd guess that only the $('#DeleteModal').modal('hide'); is relevant here?
                                                        – Rup
                                                        Jul 9 at 11:18


















                                                      Hi - thanks for your answer. I've formatted this as code (which was fairly simple - just indent the first line a bit more). However I'd guess that only the $('#DeleteModal').modal('hide'); is relevant here?
                                                      – Rup
                                                      Jul 9 at 11:18






                                                      Hi - thanks for your answer. I've formatted this as code (which was fairly simple - just indent the first line a bit more). However I'd guess that only the $('#DeleteModal').modal('hide'); is relevant here?
                                                      – Rup
                                                      Jul 9 at 11:18












                                                      up vote
                                                      4
                                                      down vote













                                                      $('.modal.in').modal('hide');



                                                      use the above code to hide the backdrop of modal if you are using multiple modal pop in one page.






                                                      share|improve this answer



























                                                        up vote
                                                        4
                                                        down vote













                                                        $('.modal.in').modal('hide');



                                                        use the above code to hide the backdrop of modal if you are using multiple modal pop in one page.






                                                        share|improve this answer

























                                                          up vote
                                                          4
                                                          down vote










                                                          up vote
                                                          4
                                                          down vote









                                                          $('.modal.in').modal('hide');



                                                          use the above code to hide the backdrop of modal if you are using multiple modal pop in one page.






                                                          share|improve this answer














                                                          $('.modal.in').modal('hide');



                                                          use the above code to hide the backdrop of modal if you are using multiple modal pop in one page.







                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Aug 18 '17 at 14:52









                                                          Vini.g.fer

                                                          4,83583459




                                                          4,83583459










                                                          answered May 16 '17 at 16:41









                                                          sher bahadur

                                                          5416




                                                          5416






















                                                              up vote
                                                              4
                                                              down vote
















                                                              <!DOCTYPE html>
                                                              <html lang="en">
                                                              <head>
                                                              <title>Bootstrap Example</title>
                                                              <meta charset="utf-8">
                                                              <meta name="viewport" content="width=device-width, initial-scale=1">
                                                              <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
                                                              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                                                              <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
                                                              <script>
                                                              $(window).load(function(){
                                                              $('#myModal').modal('show');
                                                              });
                                                              $(function () {
                                                              $('#modal').modal('toggle');
                                                              });
                                                              </script>
                                                              </head>
                                                              <body>

                                                              <div class="container">
                                                              <h2>Modal Example</h2>
                                                              <!-- Trigger the modal with a button -->
                                                              <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

                                                              <!-- Modal -->
                                                              <div class="modal fade" id="myModal" role="dialog">
                                                              <div class="modal-dialog">

                                                              <!-- Modal content-->
                                                              <div class="modal-content">
                                                              <div class="modal-header">
                                                              <button type="button" class="close" data-dismiss="modal">&times;</button>
                                                              <h4 class="modal-title">Modal Header</h4>
                                                              </div>
                                                              <div class="modal-body">
                                                              <p>Some text in the modal.</p>
                                                              </div>
                                                              <div class="modal-footer">
                                                              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                                              </div>
                                                              </div>

                                                              </div>
                                                              </div>

                                                              </div>

                                                              </body>
                                                              </html>








                                                              share|improve this answer























                                                              • Error: "message": "Uncaught TypeError: $(...).modal is not a function"
                                                                – Ivan Burlutskiy
                                                                Dec 9 '17 at 21:15










                                                              • you got this error?
                                                                – Ganesh Putta
                                                                Dec 11 '17 at 4:41










                                                              • Yes. I have the error if "Run code snippet" in Chrome (Linux Mint). But it works in Firefox.
                                                                – Ivan Burlutskiy
                                                                Dec 11 '17 at 6:54






                                                              • 1




                                                                @Ivan Burlutskiy, Thank u for informing me, These is a issue with jquery include, so i fixed it. now it works fine in all browsers.
                                                                – Ganesh Putta
                                                                Dec 11 '17 at 7:10















                                                              up vote
                                                              4
                                                              down vote
















                                                              <!DOCTYPE html>
                                                              <html lang="en">
                                                              <head>
                                                              <title>Bootstrap Example</title>
                                                              <meta charset="utf-8">
                                                              <meta name="viewport" content="width=device-width, initial-scale=1">
                                                              <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
                                                              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                                                              <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
                                                              <script>
                                                              $(window).load(function(){
                                                              $('#myModal').modal('show');
                                                              });
                                                              $(function () {
                                                              $('#modal').modal('toggle');
                                                              });
                                                              </script>
                                                              </head>
                                                              <body>

                                                              <div class="container">
                                                              <h2>Modal Example</h2>
                                                              <!-- Trigger the modal with a button -->
                                                              <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

                                                              <!-- Modal -->
                                                              <div class="modal fade" id="myModal" role="dialog">
                                                              <div class="modal-dialog">

                                                              <!-- Modal content-->
                                                              <div class="modal-content">
                                                              <div class="modal-header">
                                                              <button type="button" class="close" data-dismiss="modal">&times;</button>
                                                              <h4 class="modal-title">Modal Header</h4>
                                                              </div>
                                                              <div class="modal-body">
                                                              <p>Some text in the modal.</p>
                                                              </div>
                                                              <div class="modal-footer">
                                                              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                                              </div>
                                                              </div>

                                                              </div>
                                                              </div>

                                                              </div>

                                                              </body>
                                                              </html>








                                                              share|improve this answer























                                                              • Error: "message": "Uncaught TypeError: $(...).modal is not a function"
                                                                – Ivan Burlutskiy
                                                                Dec 9 '17 at 21:15










                                                              • you got this error?
                                                                – Ganesh Putta
                                                                Dec 11 '17 at 4:41










                                                              • Yes. I have the error if "Run code snippet" in Chrome (Linux Mint). But it works in Firefox.
                                                                – Ivan Burlutskiy
                                                                Dec 11 '17 at 6:54






                                                              • 1




                                                                @Ivan Burlutskiy, Thank u for informing me, These is a issue with jquery include, so i fixed it. now it works fine in all browsers.
                                                                – Ganesh Putta
                                                                Dec 11 '17 at 7:10













                                                              up vote
                                                              4
                                                              down vote










                                                              up vote
                                                              4
                                                              down vote












                                                              <!DOCTYPE html>
                                                              <html lang="en">
                                                              <head>
                                                              <title>Bootstrap Example</title>
                                                              <meta charset="utf-8">
                                                              <meta name="viewport" content="width=device-width, initial-scale=1">
                                                              <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
                                                              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                                                              <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
                                                              <script>
                                                              $(window).load(function(){
                                                              $('#myModal').modal('show');
                                                              });
                                                              $(function () {
                                                              $('#modal').modal('toggle');
                                                              });
                                                              </script>
                                                              </head>
                                                              <body>

                                                              <div class="container">
                                                              <h2>Modal Example</h2>
                                                              <!-- Trigger the modal with a button -->
                                                              <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

                                                              <!-- Modal -->
                                                              <div class="modal fade" id="myModal" role="dialog">
                                                              <div class="modal-dialog">

                                                              <!-- Modal content-->
                                                              <div class="modal-content">
                                                              <div class="modal-header">
                                                              <button type="button" class="close" data-dismiss="modal">&times;</button>
                                                              <h4 class="modal-title">Modal Header</h4>
                                                              </div>
                                                              <div class="modal-body">
                                                              <p>Some text in the modal.</p>
                                                              </div>
                                                              <div class="modal-footer">
                                                              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                                              </div>
                                                              </div>

                                                              </div>
                                                              </div>

                                                              </div>

                                                              </body>
                                                              </html>








                                                              share|improve this answer

















                                                              <!DOCTYPE html>
                                                              <html lang="en">
                                                              <head>
                                                              <title>Bootstrap Example</title>
                                                              <meta charset="utf-8">
                                                              <meta name="viewport" content="width=device-width, initial-scale=1">
                                                              <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
                                                              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                                                              <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
                                                              <script>
                                                              $(window).load(function(){
                                                              $('#myModal').modal('show');
                                                              });
                                                              $(function () {
                                                              $('#modal').modal('toggle');
                                                              });
                                                              </script>
                                                              </head>
                                                              <body>

                                                              <div class="container">
                                                              <h2>Modal Example</h2>
                                                              <!-- Trigger the modal with a button -->
                                                              <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

                                                              <!-- Modal -->
                                                              <div class="modal fade" id="myModal" role="dialog">
                                                              <div class="modal-dialog">

                                                              <!-- Modal content-->
                                                              <div class="modal-content">
                                                              <div class="modal-header">
                                                              <button type="button" class="close" data-dismiss="modal">&times;</button>
                                                              <h4 class="modal-title">Modal Header</h4>
                                                              </div>
                                                              <div class="modal-body">
                                                              <p>Some text in the modal.</p>
                                                              </div>
                                                              <div class="modal-footer">
                                                              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                                              </div>
                                                              </div>

                                                              </div>
                                                              </div>

                                                              </div>

                                                              </body>
                                                              </html>








                                                              <!DOCTYPE html>
                                                              <html lang="en">
                                                              <head>
                                                              <title>Bootstrap Example</title>
                                                              <meta charset="utf-8">
                                                              <meta name="viewport" content="width=device-width, initial-scale=1">
                                                              <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
                                                              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                                                              <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
                                                              <script>
                                                              $(window).load(function(){
                                                              $('#myModal').modal('show');
                                                              });
                                                              $(function () {
                                                              $('#modal').modal('toggle');
                                                              });
                                                              </script>
                                                              </head>
                                                              <body>

                                                              <div class="container">
                                                              <h2>Modal Example</h2>
                                                              <!-- Trigger the modal with a button -->
                                                              <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

                                                              <!-- Modal -->
                                                              <div class="modal fade" id="myModal" role="dialog">
                                                              <div class="modal-dialog">

                                                              <!-- Modal content-->
                                                              <div class="modal-content">
                                                              <div class="modal-header">
                                                              <button type="button" class="close" data-dismiss="modal">&times;</button>
                                                              <h4 class="modal-title">Modal Header</h4>
                                                              </div>
                                                              <div class="modal-body">
                                                              <p>Some text in the modal.</p>
                                                              </div>
                                                              <div class="modal-footer">
                                                              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                                              </div>
                                                              </div>

                                                              </div>
                                                              </div>

                                                              </div>

                                                              </body>
                                                              </html>





                                                              <!DOCTYPE html>
                                                              <html lang="en">
                                                              <head>
                                                              <title>Bootstrap Example</title>
                                                              <meta charset="utf-8">
                                                              <meta name="viewport" content="width=device-width, initial-scale=1">
                                                              <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
                                                              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                                                              <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
                                                              <script>
                                                              $(window).load(function(){
                                                              $('#myModal').modal('show');
                                                              });
                                                              $(function () {
                                                              $('#modal').modal('toggle');
                                                              });
                                                              </script>
                                                              </head>
                                                              <body>

                                                              <div class="container">
                                                              <h2>Modal Example</h2>
                                                              <!-- Trigger the modal with a button -->
                                                              <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

                                                              <!-- Modal -->
                                                              <div class="modal fade" id="myModal" role="dialog">
                                                              <div class="modal-dialog">

                                                              <!-- Modal content-->
                                                              <div class="modal-content">
                                                              <div class="modal-header">
                                                              <button type="button" class="close" data-dismiss="modal">&times;</button>
                                                              <h4 class="modal-title">Modal Header</h4>
                                                              </div>
                                                              <div class="modal-body">
                                                              <p>Some text in the modal.</p>
                                                              </div>
                                                              <div class="modal-footer">
                                                              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                                              </div>
                                                              </div>

                                                              </div>
                                                              </div>

                                                              </div>

                                                              </body>
                                                              </html>






                                                              share|improve this answer














                                                              share|improve this answer



                                                              share|improve this answer








                                                              edited Dec 11 '17 at 7:04

























                                                              answered Jul 20 '16 at 9:54









                                                              Ganesh Putta

                                                              2,206918




                                                              2,206918












                                                              • Error: "message": "Uncaught TypeError: $(...).modal is not a function"
                                                                – Ivan Burlutskiy
                                                                Dec 9 '17 at 21:15










                                                              • you got this error?
                                                                – Ganesh Putta
                                                                Dec 11 '17 at 4:41










                                                              • Yes. I have the error if "Run code snippet" in Chrome (Linux Mint). But it works in Firefox.
                                                                – Ivan Burlutskiy
                                                                Dec 11 '17 at 6:54






                                                              • 1




                                                                @Ivan Burlutskiy, Thank u for informing me, These is a issue with jquery include, so i fixed it. now it works fine in all browsers.
                                                                – Ganesh Putta
                                                                Dec 11 '17 at 7:10


















                                                              • Error: "message": "Uncaught TypeError: $(...).modal is not a function"
                                                                – Ivan Burlutskiy
                                                                Dec 9 '17 at 21:15










                                                              • you got this error?
                                                                – Ganesh Putta
                                                                Dec 11 '17 at 4:41










                                                              • Yes. I have the error if "Run code snippet" in Chrome (Linux Mint). But it works in Firefox.
                                                                – Ivan Burlutskiy
                                                                Dec 11 '17 at 6:54






                                                              • 1




                                                                @Ivan Burlutskiy, Thank u for informing me, These is a issue with jquery include, so i fixed it. now it works fine in all browsers.
                                                                – Ganesh Putta
                                                                Dec 11 '17 at 7:10
















                                                              Error: "message": "Uncaught TypeError: $(...).modal is not a function"
                                                              – Ivan Burlutskiy
                                                              Dec 9 '17 at 21:15




                                                              Error: "message": "Uncaught TypeError: $(...).modal is not a function"
                                                              – Ivan Burlutskiy
                                                              Dec 9 '17 at 21:15












                                                              you got this error?
                                                              – Ganesh Putta
                                                              Dec 11 '17 at 4:41




                                                              you got this error?
                                                              – Ganesh Putta
                                                              Dec 11 '17 at 4:41












                                                              Yes. I have the error if "Run code snippet" in Chrome (Linux Mint). But it works in Firefox.
                                                              – Ivan Burlutskiy
                                                              Dec 11 '17 at 6:54




                                                              Yes. I have the error if "Run code snippet" in Chrome (Linux Mint). But it works in Firefox.
                                                              – Ivan Burlutskiy
                                                              Dec 11 '17 at 6:54




                                                              1




                                                              1




                                                              @Ivan Burlutskiy, Thank u for informing me, These is a issue with jquery include, so i fixed it. now it works fine in all browsers.
                                                              – Ganesh Putta
                                                              Dec 11 '17 at 7:10




                                                              @Ivan Burlutskiy, Thank u for informing me, These is a issue with jquery include, so i fixed it. now it works fine in all browsers.
                                                              – Ganesh Putta
                                                              Dec 11 '17 at 7:10










                                                              up vote
                                                              3
                                                              down vote













                                                              Using modal.hide would only hide the modal. If you are using overlay underneath the modal, it would still be there. use click call to actually close the modal and remove the overlay.



                                                              $("#modalID .close").click()





                                                              share|improve this answer





















                                                              • this is correct one
                                                                – Veshraj Joshi
                                                                Mar 6 '17 at 4:23















                                                              up vote
                                                              3
                                                              down vote













                                                              Using modal.hide would only hide the modal. If you are using overlay underneath the modal, it would still be there. use click call to actually close the modal and remove the overlay.



                                                              $("#modalID .close").click()





                                                              share|improve this answer





















                                                              • this is correct one
                                                                – Veshraj Joshi
                                                                Mar 6 '17 at 4:23













                                                              up vote
                                                              3
                                                              down vote










                                                              up vote
                                                              3
                                                              down vote









                                                              Using modal.hide would only hide the modal. If you are using overlay underneath the modal, it would still be there. use click call to actually close the modal and remove the overlay.



                                                              $("#modalID .close").click()





                                                              share|improve this answer












                                                              Using modal.hide would only hide the modal. If you are using overlay underneath the modal, it would still be there. use click call to actually close the modal and remove the overlay.



                                                              $("#modalID .close").click()






                                                              share|improve this answer












                                                              share|improve this answer



                                                              share|improve this answer










                                                              answered Feb 22 '17 at 22:39









                                                              Vikalp Veer

                                                              1115




                                                              1115












                                                              • this is correct one
                                                                – Veshraj Joshi
                                                                Mar 6 '17 at 4:23


















                                                              • this is correct one
                                                                – Veshraj Joshi
                                                                Mar 6 '17 at 4:23
















                                                              this is correct one
                                                              – Veshraj Joshi
                                                              Mar 6 '17 at 4:23




                                                              this is correct one
                                                              – Veshraj Joshi
                                                              Mar 6 '17 at 4:23










                                                              up vote
                                                              3
                                                              down vote













                                                              you can use;



                                                              $('#' + $('.modal.show').attr('id')).modal('hide');





                                                              share|improve this answer

























                                                                up vote
                                                                3
                                                                down vote













                                                                you can use;



                                                                $('#' + $('.modal.show').attr('id')).modal('hide');





                                                                share|improve this answer























                                                                  up vote
                                                                  3
                                                                  down vote










                                                                  up vote
                                                                  3
                                                                  down vote









                                                                  you can use;



                                                                  $('#' + $('.modal.show').attr('id')).modal('hide');





                                                                  share|improve this answer












                                                                  you can use;



                                                                  $('#' + $('.modal.show').attr('id')).modal('hide');






                                                                  share|improve this answer












                                                                  share|improve this answer



                                                                  share|improve this answer










                                                                  answered Apr 5 at 12:53









                                                                  Fatih Turan

                                                                  334




                                                                  334






















                                                                      up vote
                                                                      2
                                                                      down vote













                                                                      Another way of doing this is that first you remove the class modal-open, which closes the modal. Then you remove the class modal-backdrop that removes the grayish cover of the modal.



                                                                      Following code can be used:



                                                                      $('body').removeClass('modal-open')
                                                                      $('.modal-backdrop').remove()





                                                                      share|improve this answer























                                                                      • Please try to avoid just dumping code as an answer and try to explain what it does and why. Your code might not be obvious for people who do not have the relevant coding experience. Please edit your answer to include clarification, context and try to mention any limitations, assumptions or simplifications in your answer.
                                                                        – Frits
                                                                        May 31 '17 at 6:24










                                                                      • OK, so basically what this does is removes the class modal-open, which closes the modal. then removes the class modal-backdrop that removes the grayish cover of the modal
                                                                        – Orozcorp
                                                                        May 31 '17 at 21:17















                                                                      up vote
                                                                      2
                                                                      down vote













                                                                      Another way of doing this is that first you remove the class modal-open, which closes the modal. Then you remove the class modal-backdrop that removes the grayish cover of the modal.



                                                                      Following code can be used:



                                                                      $('body').removeClass('modal-open')
                                                                      $('.modal-backdrop').remove()





                                                                      share|improve this answer























                                                                      • Please try to avoid just dumping code as an answer and try to explain what it does and why. Your code might not be obvious for people who do not have the relevant coding experience. Please edit your answer to include clarification, context and try to mention any limitations, assumptions or simplifications in your answer.
                                                                        – Frits
                                                                        May 31 '17 at 6:24










                                                                      • OK, so basically what this does is removes the class modal-open, which closes the modal. then removes the class modal-backdrop that removes the grayish cover of the modal
                                                                        – Orozcorp
                                                                        May 31 '17 at 21:17













                                                                      up vote
                                                                      2
                                                                      down vote










                                                                      up vote
                                                                      2
                                                                      down vote









                                                                      Another way of doing this is that first you remove the class modal-open, which closes the modal. Then you remove the class modal-backdrop that removes the grayish cover of the modal.



                                                                      Following code can be used:



                                                                      $('body').removeClass('modal-open')
                                                                      $('.modal-backdrop').remove()





                                                                      share|improve this answer














                                                                      Another way of doing this is that first you remove the class modal-open, which closes the modal. Then you remove the class modal-backdrop that removes the grayish cover of the modal.



                                                                      Following code can be used:



                                                                      $('body').removeClass('modal-open')
                                                                      $('.modal-backdrop').remove()






                                                                      share|improve this answer














                                                                      share|improve this answer



                                                                      share|improve this answer








                                                                      edited Aug 17 '17 at 8:35









                                                                      madforstrength

                                                                      1,3041921




                                                                      1,3041921










                                                                      answered May 30 '17 at 15:26









                                                                      Orozcorp

                                                                      9419




                                                                      9419












                                                                      • Please try to avoid just dumping code as an answer and try to explain what it does and why. Your code might not be obvious for people who do not have the relevant coding experience. Please edit your answer to include clarification, context and try to mention any limitations, assumptions or simplifications in your answer.
                                                                        – Frits
                                                                        May 31 '17 at 6:24










                                                                      • OK, so basically what this does is removes the class modal-open, which closes the modal. then removes the class modal-backdrop that removes the grayish cover of the modal
                                                                        – Orozcorp
                                                                        May 31 '17 at 21:17


















                                                                      • Please try to avoid just dumping code as an answer and try to explain what it does and why. Your code might not be obvious for people who do not have the relevant coding experience. Please edit your answer to include clarification, context and try to mention any limitations, assumptions or simplifications in your answer.
                                                                        – Frits
                                                                        May 31 '17 at 6:24










                                                                      • OK, so basically what this does is removes the class modal-open, which closes the modal. then removes the class modal-backdrop that removes the grayish cover of the modal
                                                                        – Orozcorp
                                                                        May 31 '17 at 21:17
















                                                                      Please try to avoid just dumping code as an answer and try to explain what it does and why. Your code might not be obvious for people who do not have the relevant coding experience. Please edit your answer to include clarification, context and try to mention any limitations, assumptions or simplifications in your answer.
                                                                      – Frits
                                                                      May 31 '17 at 6:24




                                                                      Please try to avoid just dumping code as an answer and try to explain what it does and why. Your code might not be obvious for people who do not have the relevant coding experience. Please edit your answer to include clarification, context and try to mention any limitations, assumptions or simplifications in your answer.
                                                                      – Frits
                                                                      May 31 '17 at 6:24












                                                                      OK, so basically what this does is removes the class modal-open, which closes the modal. then removes the class modal-backdrop that removes the grayish cover of the modal
                                                                      – Orozcorp
                                                                      May 31 '17 at 21:17




                                                                      OK, so basically what this does is removes the class modal-open, which closes the modal. then removes the class modal-backdrop that removes the grayish cover of the modal
                                                                      – Orozcorp
                                                                      May 31 '17 at 21:17










                                                                      up vote
                                                                      2
                                                                      down vote













                                                                      In my case, main page from where bootstrap modal was triggered started to not responding after using $("#modal").modal('toggle'); way, but started responding in the following way:



                                                                      $("#submitBtn").on("click",function(){
                                                                      $("#submitBtn").attr("data-dismiss","modal");
                                                                      });





                                                                      share|improve this answer























                                                                      • Genius! Best working solution +1
                                                                        – Zohab Ali
                                                                        Jun 4 at 9:31















                                                                      up vote
                                                                      2
                                                                      down vote













                                                                      In my case, main page from where bootstrap modal was triggered started to not responding after using $("#modal").modal('toggle'); way, but started responding in the following way:



                                                                      $("#submitBtn").on("click",function(){
                                                                      $("#submitBtn").attr("data-dismiss","modal");
                                                                      });





                                                                      share|improve this answer























                                                                      • Genius! Best working solution +1
                                                                        – Zohab Ali
                                                                        Jun 4 at 9:31













                                                                      up vote
                                                                      2
                                                                      down vote










                                                                      up vote
                                                                      2
                                                                      down vote









                                                                      In my case, main page from where bootstrap modal was triggered started to not responding after using $("#modal").modal('toggle'); way, but started responding in the following way:



                                                                      $("#submitBtn").on("click",function(){
                                                                      $("#submitBtn").attr("data-dismiss","modal");
                                                                      });





                                                                      share|improve this answer














                                                                      In my case, main page from where bootstrap modal was triggered started to not responding after using $("#modal").modal('toggle'); way, but started responding in the following way:



                                                                      $("#submitBtn").on("click",function(){
                                                                      $("#submitBtn").attr("data-dismiss","modal");
                                                                      });






                                                                      share|improve this answer














                                                                      share|improve this answer



                                                                      share|improve this answer








                                                                      edited Jul 20 at 13:43









                                                                      alexP

                                                                      2,21321330




                                                                      2,21321330










                                                                      answered Mar 29 at 10:16









                                                                      Awais Nasir

                                                                      356




                                                                      356












                                                                      • Genius! Best working solution +1
                                                                        – Zohab Ali
                                                                        Jun 4 at 9:31


















                                                                      • Genius! Best working solution +1
                                                                        – Zohab Ali
                                                                        Jun 4 at 9:31
















                                                                      Genius! Best working solution +1
                                                                      – Zohab Ali
                                                                      Jun 4 at 9:31




                                                                      Genius! Best working solution +1
                                                                      – Zohab Ali
                                                                      Jun 4 at 9:31










                                                                      up vote
                                                                      1
                                                                      down vote













                                                                      Besides, you can "click" on a 'x', that closes dialog.
                                                                      E.g.:



                                                                      $(".ui-dialog-titlebar-close").click();






                                                                      share|improve this answer

























                                                                        up vote
                                                                        1
                                                                        down vote













                                                                        Besides, you can "click" on a 'x', that closes dialog.
                                                                        E.g.:



                                                                        $(".ui-dialog-titlebar-close").click();






                                                                        share|improve this answer























                                                                          up vote
                                                                          1
                                                                          down vote










                                                                          up vote
                                                                          1
                                                                          down vote









                                                                          Besides, you can "click" on a 'x', that closes dialog.
                                                                          E.g.:



                                                                          $(".ui-dialog-titlebar-close").click();






                                                                          share|improve this answer












                                                                          Besides, you can "click" on a 'x', that closes dialog.
                                                                          E.g.:



                                                                          $(".ui-dialog-titlebar-close").click();







                                                                          share|improve this answer












                                                                          share|improve this answer



                                                                          share|improve this answer










                                                                          answered Jan 10 '17 at 21:10









                                                                          slashka

                                                                          3618




                                                                          3618






















                                                                              up vote
                                                                              1
                                                                              down vote













                                                                              This code worked perfectly for me to close a modal (i'm using bootstrap 3.3)



                                                                              $('#myModal').removeClass('in')





                                                                              share|improve this answer

























                                                                                up vote
                                                                                1
                                                                                down vote













                                                                                This code worked perfectly for me to close a modal (i'm using bootstrap 3.3)



                                                                                $('#myModal').removeClass('in')





                                                                                share|improve this answer























                                                                                  up vote
                                                                                  1
                                                                                  down vote










                                                                                  up vote
                                                                                  1
                                                                                  down vote









                                                                                  This code worked perfectly for me to close a modal (i'm using bootstrap 3.3)



                                                                                  $('#myModal').removeClass('in')





                                                                                  share|improve this answer












                                                                                  This code worked perfectly for me to close a modal (i'm using bootstrap 3.3)



                                                                                  $('#myModal').removeClass('in')






                                                                                  share|improve this answer












                                                                                  share|improve this answer



                                                                                  share|improve this answer










                                                                                  answered Mar 13 at 17:31









                                                                                  user3870075

                                                                                  6318




                                                                                  6318






















                                                                                      up vote
                                                                                      1
                                                                                      down vote














                                                                                      I closed modal Programmatically with this trick




                                                                                      Add a button in modal with data-dismiss="modal" and hide the button with display: none. Here is how it will look like



                                                                                      <div class="modal fade" id="addNewPaymentMethod" role="dialog">
                                                                                      <div class="modal-dialog">
                                                                                      .
                                                                                      .
                                                                                      .
                                                                                      <button type="button" id="close-modal" data-dismiss="modal" style="display: none">Close</button>
                                                                                      </div>
                                                                                      </div>


                                                                                      Now when you want to close modal Programmatically just trigger a click event on that button, which is not visible to user



                                                                                      In Javascript you can trigger click on that button like this:



                                                                                      document.getElementById('close-modal').click();





                                                                                      share|improve this answer

























                                                                                        up vote
                                                                                        1
                                                                                        down vote














                                                                                        I closed modal Programmatically with this trick




                                                                                        Add a button in modal with data-dismiss="modal" and hide the button with display: none. Here is how it will look like



                                                                                        <div class="modal fade" id="addNewPaymentMethod" role="dialog">
                                                                                        <div class="modal-dialog">
                                                                                        .
                                                                                        .
                                                                                        .
                                                                                        <button type="button" id="close-modal" data-dismiss="modal" style="display: none">Close</button>
                                                                                        </div>
                                                                                        </div>


                                                                                        Now when you want to close modal Programmatically just trigger a click event on that button, which is not visible to user



                                                                                        In Javascript you can trigger click on that button like this:



                                                                                        document.getElementById('close-modal').click();





                                                                                        share|improve this answer























                                                                                          up vote
                                                                                          1
                                                                                          down vote










                                                                                          up vote
                                                                                          1
                                                                                          down vote










                                                                                          I closed modal Programmatically with this trick




                                                                                          Add a button in modal with data-dismiss="modal" and hide the button with display: none. Here is how it will look like



                                                                                          <div class="modal fade" id="addNewPaymentMethod" role="dialog">
                                                                                          <div class="modal-dialog">
                                                                                          .
                                                                                          .
                                                                                          .
                                                                                          <button type="button" id="close-modal" data-dismiss="modal" style="display: none">Close</button>
                                                                                          </div>
                                                                                          </div>


                                                                                          Now when you want to close modal Programmatically just trigger a click event on that button, which is not visible to user



                                                                                          In Javascript you can trigger click on that button like this:



                                                                                          document.getElementById('close-modal').click();





                                                                                          share|improve this answer













                                                                                          I closed modal Programmatically with this trick




                                                                                          Add a button in modal with data-dismiss="modal" and hide the button with display: none. Here is how it will look like



                                                                                          <div class="modal fade" id="addNewPaymentMethod" role="dialog">
                                                                                          <div class="modal-dialog">
                                                                                          .
                                                                                          .
                                                                                          .
                                                                                          <button type="button" id="close-modal" data-dismiss="modal" style="display: none">Close</button>
                                                                                          </div>
                                                                                          </div>


                                                                                          Now when you want to close modal Programmatically just trigger a click event on that button, which is not visible to user



                                                                                          In Javascript you can trigger click on that button like this:



                                                                                          document.getElementById('close-modal').click();






                                                                                          share|improve this answer












                                                                                          share|improve this answer



                                                                                          share|improve this answer










                                                                                          answered Aug 30 at 12:19









                                                                                          Zohab Ali

                                                                                          1,1991121




                                                                                          1,1991121






















                                                                                              up vote
                                                                                              0
                                                                                              down vote













                                                                                              This works well



                                                                                              $(function () {
                                                                                              $('#modal').modal('toggle');
                                                                                              });


                                                                                              However, when you have multiple modals stacking on top one another it is not effective, so instead , this works



                                                                                              data-dismiss="modal"





                                                                                              share|improve this answer

























                                                                                                up vote
                                                                                                0
                                                                                                down vote













                                                                                                This works well



                                                                                                $(function () {
                                                                                                $('#modal').modal('toggle');
                                                                                                });


                                                                                                However, when you have multiple modals stacking on top one another it is not effective, so instead , this works



                                                                                                data-dismiss="modal"





                                                                                                share|improve this answer























                                                                                                  up vote
                                                                                                  0
                                                                                                  down vote










                                                                                                  up vote
                                                                                                  0
                                                                                                  down vote









                                                                                                  This works well



                                                                                                  $(function () {
                                                                                                  $('#modal').modal('toggle');
                                                                                                  });


                                                                                                  However, when you have multiple modals stacking on top one another it is not effective, so instead , this works



                                                                                                  data-dismiss="modal"





                                                                                                  share|improve this answer












                                                                                                  This works well



                                                                                                  $(function () {
                                                                                                  $('#modal').modal('toggle');
                                                                                                  });


                                                                                                  However, when you have multiple modals stacking on top one another it is not effective, so instead , this works



                                                                                                  data-dismiss="modal"






                                                                                                  share|improve this answer












                                                                                                  share|improve this answer



                                                                                                  share|improve this answer










                                                                                                  answered Nov 19 at 13:11









                                                                                                  Edgar256

                                                                                                  513




                                                                                                  513






























                                                                                                      draft saved

                                                                                                      draft discarded




















































                                                                                                      Thanks for contributing an answer to Stack Overflow!


                                                                                                      • Please be sure to answer the question. Provide details and share your research!

                                                                                                      But avoid



                                                                                                      • Asking for help, clarification, or responding to other answers.

                                                                                                      • Making statements based on opinion; back them up with references or personal experience.


                                                                                                      To learn more, see our tips on writing great answers.





                                                                                                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                                                                      Please pay close attention to the following guidance:


                                                                                                      • Please be sure to answer the question. Provide details and share your research!

                                                                                                      But avoid



                                                                                                      • Asking for help, clarification, or responding to other answers.

                                                                                                      • Making statements based on opinion; back them up with references or personal experience.


                                                                                                      To learn more, see our tips on writing great answers.




                                                                                                      draft saved


                                                                                                      draft discarded














                                                                                                      StackExchange.ready(
                                                                                                      function () {
                                                                                                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16493280%2fclose-bootstrap-modal%23new-answer', 'question_page');
                                                                                                      }
                                                                                                      );

                                                                                                      Post as a guest















                                                                                                      Required, but never shown





















































                                                                                                      Required, but never shown














                                                                                                      Required, but never shown












                                                                                                      Required, but never shown







                                                                                                      Required, but never shown

































                                                                                                      Required, but never shown














                                                                                                      Required, but never shown












                                                                                                      Required, but never shown







                                                                                                      Required, but never shown







                                                                                                      Popular posts from this blog

                                                                                                      "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                                                                                                      Alcedinidae

                                                                                                      Origin of the phrase “under your belt”?