I want to set the absolute position (x and y) of a jQuery UI (1.12.1) dialog. By all accounts I should be able to do that like so (although the jQuery docs inexplicably do not mention this syntax, neither here nor here):
$('#element').dialog('option', 'position', [x, y]);
Examples of people successfully using this syntax are in:
- jQuery UI dialog positioning
- Can I make jquery dialog position independent of window size?
- Lots of other places.
Yet, when I do attempt this, nothing happens. Consider the following example (might want to run full screen):
$('#test').dialog({
width: 200,
height: 200
});
$('#move').click(function () {
$('#test').dialog('option', 'position', [30, 30]);
});
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<body>
<button id="move">Move</button>
<div id="test" title="test">This is a test.</div>
</body>
Run it, press the button, the dialog does not move.
Why isn't this working for me and how do I set the x,y position of a dialog?
Note that the dialog must remain both draggable and resizable after the position change.