JQUERY, calling the dialog that I created? Not find him

I use the following code to create a dialog 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 am trying to call a dialog to open it, but JQUERY does not find it using the following:

$dialog2.dialog('open');

Strange if I add the following after the above, it works on BIND:

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

Any ideas why this is so? How can I call a dialog to open in another function?

thank

+3
source share
1 answer

You should wrap your code in a domready event handler:

$(document).ready(function() {

    $dialog2.dialog('open');

});
+2
source

Source: https://habr.com/ru/post/1729805/


All Articles