2

I am using jQuery UI to display a dialog but I would like to reposition the window exactly under the button when it opens.

Can someone help me with that?

The code:

http://jsfiddle.net/ntenisOT/vJNRj/3/

1 Answer 1

3

You can use offset() and outerHeight() to compute the appropriate coordinates, and the position option to reposition the dialog widget:

var $opener = $("#opener");
var offset = $opener.offset();
$("#dialog").dialog("option", "position",
    [offset.left, offset.top + $opener.outerHeight()]);

Updated fiddle here.

EDIT: Using the same button to close the dialog involves checking its status in your click handler:

$opener.click(function() {
    var $dialog = $("#dialog");
    var verb = $dialog.dialog("isOpen") ? "close" : "open";
    $dialog.dialog(verb);
    return false;
});

Updated fiddle there.

2
  • Thanks a lot.. Is it possible to close the dialog using the same button?? Can you please give me a hint or update jfiddle please?
    – Immo
    Commented Aug 6, 2011 at 13:22
  • Thanks a lot :) 1000% thanks.. I ll probably read more about jquery soon. It seems to be AMAZING!
    – Immo
    Commented Aug 6, 2011 at 13:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.