views:

30

answers:

1

I have a little problem closing my dialog box in javscript/jquery on mouse exit here is the script

$().ready(function () {
    $(".popup").live("mouseover", function () {

        $(this).next().dialog();
    });
    $(".popup").live("mouseout", function () {

        $(this).next().close();
    });
});
+2  A: 

Something like this will work:

$(function () {
  $(".popup").live("mouseover", function () {
    var dlg = $.data(this, 'dialog');
    if(dlg) dlg.dialog('open');
    else $.data(this, 'dialog', $(this).next().dialog());
  }).live("mouseout", function () {
    $.data(this, 'dialog').dialog('close');
  });
});

Why is it that complicated? Well the .dialog() call wraps the element and moves it to the end of the <body> element, so .next() won't find it anymore. So...we need to store a reference to the relevant dialog.

An alternative would be to position the dialog and stick it back in the DOM in a relative way when creating it, either way works.

Nick Craver
Thank you it worked :)
Profeten
@Profeten - welcome :)
Nick Craver