question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modal Disappears Immediately

See original GitHub issue

I’m using Bootstrap 2.0 and am trying to use a Modal for displaying a Markdown cheat sheet. I’ve set up a link to display the modal but when I click it, the modal appears briefly and then immediately disappears again.

Here’s my basic code:

<a class="btn" data-toggle="modal" data-target="#markdown">Show Markdown Cheatsheet</a>

<div id="markdown" class="modal hide fade">
    Foo
</div>

I’ve got the following JS files loaded:

  • jquery 1.7.1
  • bootstrap
  • bootstrap-alert
  • bootstrap-dropdown
  • bootstrap-tabs
  • bootstrap-modal
  • bootstrap-transition
  • jquery.dataTables.min

I have the following document-ready blocks:

$(document).ready(function(){
    $(".alert-message").alert();
    $(".dropdown-toggle").dropdown();

    $('#save').attr("disabled", "disabled");
    $('#comment_message').show();

    $('#comment').keyup(function() {
             inspectCommentTextField();
    });

    $('#minor_revision').change(function() {
         inspectMinorRevisionCheckBox();
    });

   });

$(document).ready(function(){
    computersTable = $('#computers').dataTable({
            "sScrollY": "200px",
        "bPaginate": false
    });

    applicationsTable = $('#applications').dataTable({
            "sScrollY": "200px",
        "bPaginate": false
        });

       $('form').submit(function() {
        // Clear filters because filtered checkboxes don't get submitted for some reason
        computersTable.fnFilter('');
        applicationsTable.fnFilter('');
        });
});

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:28 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
hamiltopcommented, Jun 5, 2012

For anyone who wants to understand why including both breaks things it is because of the behavior of toggle(). With both files included, the callback function for click is bound twice and is therefore called twice. The first time it is called it shows the modal dialogue, and the second time it hides it. It does this so fast it looks like nothing happens.

I’ve seen people spend hours scratching their head over this and similar situations. Is there anyway to simulate the classic C #ifndef code in javascript? If each plugin were to register itself with jQuery or Bootstrap or something before it binds all callbacks, it would save a lot of people headaches. It could even print a message saying “duplicate plugins” or something so developers can be made aware of the problem.

Anything like that possible?

0reactions
hp82415commented, Mar 12, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

Bootstrap Modal immediately disappearing - Stack Overflow
Change the button to anchor tag it should work, the problem occurs due to its type button as it is trying to submit...
Read more >
Modal Popup disappears immediately when called ... - MSDN
However, when i click on the button when on the Partial View, i see the modal popup but just for 2 seconds and...
Read more >
modal window disappears right after opening - WordPress.org
I have a modal window that opens but disappears immediately, and as a matter of fact I think that removing something that's needed...
Read more >
Bootstrap Modal Closes Immediately - JavaScript - SitePoint
Hi, I would like to ask why does my modal closes immediately when I hit the button to open it? Here's the link...
Read more >
[Best solution]-Modal Immediately Closes - appsloveworld.com
Problem: I am having an issue where when the user clicks on the modal "Privacy Notice" on the footer. Every time the user...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found