0

I was unable to figure out why calling setMainWindowSize below from outside of the jQuery function will not work. Somebody help? Thank you.

<script type="text/javascript">
    var mainWindowDiv =  $('<div />', {'id': 'mainWindow', 'title': 'Main Window'});
    $(function (){
            $('body').append(mainWindowDiv);
            mainWindowDiv.dialog({
                position: 'center',
                resizable: true,
            });
            //this would work
            setMainWindowSize(800,600);
    });

    function setMainWindowSize(width, height)
    {
        mainWindowDiv.dialog('option', 'width', width);
        mainWindowDiv.dialog('option', 'height', height);
    };

    //this will fail
    setMainWindowSize(800,600);
</script>

2 Answers 2

1

i believe that $(function (){ waits for the document to be ready before firing. the setMainWindowSize(800,600); you have at the end fires off first since its outside of the ready function.

ideally you would have your all of your code inside your $(function(){ });

Sign up to request clarification or add additional context in comments.

Comments

0

setMainWindowSize(800,600); should be called after the DOM is ready. Here you're calling it even before the div contains a dialog box.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.