Imdad
Imdad

Reputation: 6032

If a div is not dialog then make it dialog otherwise don't

I have a div:

<div id="dialog">Dialog content here</div>

I have a function:

function process() {
    $("#dialog").dialog({autoOpen:false});
}

I make the dialog only if it is not already created. How can I do that?

Upvotes: 0

Views: 49

Answers (2)

sinni800
sinni800

Reputation: 1449

Just put $("#dialog").dialog({autoOpen:false}); into your document.ready() event. Finally, in your process() function, add

$( "#dialog" ).dialog( "open" );

Upvotes: 0

Engineer
Engineer

Reputation: 48793

Check the data. If the dialog is created on the element, then it has 'dialog' as a property of the data:

function process()
{
    if( !$('#dialog').data('dialog') ){
        $("#dialog").dialog({autoOpen:false});
    }
}

Upvotes: 3

Related Questions