Search code examples
jquery-uidialogposition

Refresh jquery ui dialog position


I'm using a jquery dialog. The content of this dialog is dynamic so the height change when the dialog is open.

$("#a_div").dialog({ width: 400 });

The dialog initially appears center in the page. but when the height change is no more center.

How can i refresh the dialog's position without close and reopen it?

thanks


Solution

  • You need to re-set the position by doing:

    $("#a_div").dialog({
        position: { 'my': 'center', 'at': 'center' }
    });
    

    The position is set once when creating the dialog, but can be altered afterwards (or just re-set at the same value, forcing jQuery to recalculate).

    See this demo: http://jsfiddle.net/petermorlion/3wNUq/2/