Modal-dialog won't hide on page load
Asked Answered
O

2

8

I am trying to create a modal dialog to just show content (html of some sort or other):

<script>
$.fx.speeds._default = 1000;
$(function() {
    $( "#dialog" ).dialog({
        autoOpen: false,
        closeOnEscape: true,
        modal: true,
        position: 'center',
        width: 800,
        height: 600,
        show: "blind",
        hide: "explode"
    });

    $( "#opener" ).click(function() {
        $( "#dialog" ).dialog( "open" );
        return false;
    });

});
</script>

When I view the page, the dialog is inline and not hidden. Here is my html:

<div id="dialog">This is my dialog that should be hidden until called</div>
<button id="opener">I Open the Dialog</button>

What am I doing wrong?

Outwork answered 27/9, 2011 at 18:29 Comment(1)
Are you including jQueryUI.js in the right order? It seems like it isn't working at all so maybe you don't have access to jQueryUI.Truckage
S
11

Hide the div using css like such:

<div id="dialog" style="display:none;">This is my dialog that should be hidden until called</div>

Now it will only show when called upon.

Scheffler answered 15/4, 2014 at 22:38 Comment(0)
T
8

You should set the autoOpen property to false, below is some reference

http://jqueryui.com/demos/dialog/#option-autoOpen

Here is an example

$(function() {
    $( "#dialog" ).dialog({
        closeOnEscape: true,
        modal: true,
        position: 'top',
        width: 800,
        height: 600,
        show: "blind",
        hide: "explode",
        autoOpen: false  ///added this line
    });

    $( "#opener" ).click(function() {
        $( "#dialog" ).dialog( "open" );
        return false;
    });

});
Transpolar answered 27/9, 2011 at 18:35 Comment(2)
Tried that, My dialog still shows up inline and is not hidden. Thanks though.Outwork
Hi Steele, Did you get any solution to the issue that on load dialog is visible ?Nonessential

© 2022 - 2024 — McMap. All rights reserved.