Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect when any dialog opens jQuery

I have several dialogs that open like this

 $("#dialog").load(URL);
 $("#dialog").dialog(
           attributes,
           here,
           close: function(e,u) {
                    cleanup
           }

The issue is that I have hundreds of these dialogs. I do not want to manually have to create an open: attribute for each one. Is there any way I can monitor the entire document for a dialog open such as

 $(document).on("open","#dialog",function() {
     Do something
 })
like image 846
user974896 Avatar asked Dec 19 '12 16:12

user974896


People also ask

What is jQuery UI dialog?

The jQuery UI dialog method is used to create a basic dialog window which is positioned into the viewport and protected from page content. It has a title bar and a content area, and can be moved, resized and closed with the 'x' icon by default.


1 Answers

From jQuery API:

$( ".selector" ).on( "dialogopen", function( event, ui ) {} );

So you could do what you said probably:

$("body").on("dialogopen",function(e,u){
    alert('dialog open!');
});
like image 128
Tim Withers Avatar answered Oct 04 '22 07:10

Tim Withers