views:

51

answers:

1

Hello,

I'm using the following code to create a Dialog box using JQUERY/UI:

var $dialog2 = $('<div id="sharerdialog2"></div>')
.html('<p>Loading...</p>')
.dialog({
    autoOpen: false,
    title: 'Image Stuffer',
    position: ['center',150],
    width: 450,
    focus:function(event, ui) {
        $('#dialogcloser').click(function() {
            $dialog.dialog('close');
        });
    }, 
    open: function(event, ui) {
        $("#sharerdialog2").load("MyURL.com");
    }
});

I'm trying to call the Dialog to have it open, but JQUERY isn't finding it using the following:

$dialog2.dialog('open');

Strangely, if I add the following after the above, it does work on a BIND:

$('#ttttt').click(function() {
$dialog2.dialog('open');
}); 

Any ideas why this is? How can I call the Dialog to open in another function?

Thanks

+2  A: 

You should wrap your code in a domready event handler:

$(document).ready(function() {

    $dialog2.dialog('open');

});
Philippe Leybaert
I think you have to wrap all of the code in the ready handler.
DaveS
That's not necessary. The other code doesn't manipulate the DOM. It simply creates an object ready to be inserted in the DOM later on
Philippe Leybaert