How to find all dialogs in jQuery

I am trying to associate an event with all the dialog boxes that were created on the page using the JQuery UI Dialog function (regardless of whether they were shown or not). I can't seem to figure out which selector will deliver me. I tried both .ui-dialog and .ui-dialog-content without success.

Since I am trying to create a generic method, I will not know the identifiers of the dialogs that can be created.

I am using the following code for testing. It works if I specify the dialog identifier ( #mydialog ), but during the production process I will not know them.

 $("div.ui-dialog").bind("dialogclose", function(event, ui) { window.alert("close fired"); } 
+6
jquery-ui-dialog
source share
2 answers

Do your dialogs have a common class with which you can select them? If they all have a ui-dialog class, this will work:

 $(".ui-dialog") 

Your example

 $("div.ui-dialog") 

Asks to select all divs with the ui-dialog class, which probably should also work as long as the class is passed to the div element.

Perhaps the problem is that you bind the elements of dialogue before they exist? Instead, you can use the .live () function to bind to any dialogs created at any point, and not just those that exist when the function is called.

Posting an HTML snippet will help.

+7
source share

You can use this:

 $(":ui-dialog").each(function(){ "enter your code here" }) 
+2
source share

All Articles