Search code examples
javascriptjquerysimplemodal

Calling simplemodal jumps to the homescreen


Am trying to open up an image in a modal. So far everything is working good. Just having one problem.

Am having a homescreen with tabs in the footer. Now one tab opens up content/index.html So like, the page opens as index.html#content/index.html

Am loading a modal onclick of an image in the content/index.html file with

onclick = "$('#basic-modal-content').modal();"

Now, this opens the modal well, but it opens on the homescreen rather than on the same screen.

Please help.


Solution

  • if you have href="#" then you need to prevent default browser behavior which is jump to id with # or if the id is not there jump to top:

    onclick="$('#basic-modal-content').modal(); return false;"
    

    but you should not use onclick attribute insitead use jQuery click function:

    $('your link selector').click(function(e) {
       $('#basic-modal-content').modal();
       return false; // or e.preventDefault();
    });