JQuery beforeClose empties the dialog much faster than closing - why?

Suppose I am creating a dialog with jQuery (1.7.1 if applicable). A div (let's call it "divToEmpty") opens in a dialog box that can contain thousands of text divs inside. Suppose further that I want to close the above dialog div.

There are 2 options:

// options 1

$('#divToEmpty').dialog({
    beforeClose: function() {
        $('#divToEmpty').html('');
    }
});

// option 2

$('#divToEmpty').dialog({
    close: function() {
        $('#divToEmpty').html('');
    }
});

      

Option 1 is much, much faster than option 2 (which splits the jQuery script on a fairly large number of inner divs).

Why?

My hypothesis is that resetting the close dialog (DOM cascades and styling changes or something) creates an infinite loop that can be avoided if you reset the div first and then close the dialog. But this funky idea on its own ...

+3


source to share





All Articles