Today I was doing something funky with my code. I was using bootstrap 3 on my website and doing my funky code, I ran into a situation where I need to trigger a modal when a button was clicked.

I got it to work, but when the close button was clicked inside the modal, nothing would happen and it would not work.

after playing around a bit, this is how I was able to get it close. I placed this javascript code using jquery.

This is the HTML for the close button:

<input type="button" class="btn btn-danger pull-right" value="Cancel" data-dismiss="modal">

after I added the following javascript code, it worked:

        $('[data-dismiss]').on('click', function(){
                $('.modal').remove();
                $('body').removeClass('modal-open');
                $('.modal-backdrop').remove();
            });

Hope that helps if you are stuck with a modal or maybe you are stuck with a modal that closes but the background is dark and even if its not dark, the scroll might be disabled. Well, with this code, it gets rid of the .modal, removes the .model-open from the body tag and removes the modal-backdrop. I am not sure at this point what consequences this all will have on other modals after this code executes. If I see other issues, I will post them here.