close a popup with javascript

  • 2
  • Question
  • Updated 2 years ago
  • Answered
I asked this the other day and Zack wrote a snippet for closing 1 popup. Now I need to close 2.
I tried modifying the snippet, but can't get it to work
 close_popup = function(){         var popup_array = skuid.$('.ui-dialog-content');
         for (i = 0; i < popup_array.length; i++){
        popup_array[i].dialog('destroy');
        popup_array[i].remove();}
    };
i do get the array, which appears to have dom elements in it, but i get "undefined is not a function" when i try and call destroy
do i have to somehow transform the array item into something jquery can call 'dialog' on ?
Photo of ktyler

ktyler

  • 9,244 Points 5k badge 2x thumb

Posted 4 years ago

  • 2
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
This will close, destroy, and remove all open popups on the screen:

skuid.$('.ui-dialog-content').dialog('close');
Photo of ktyler

ktyler

  • 9,244 Points 5k badge 2x thumb
Thanks Zach,
I was  trying to hard, I guess.
Ken
Photo of Griffin Brown

Griffin Brown

  • 2,766 Points 2k badge 2x thumb
Is there an easy way to have it close the window as well?
Photo of Griffin Brown

Griffin Brown

  • 2,766 Points 2k badge 2x thumb
#mustlearnjavascript

#Ihatedumbquestions
Photo of Craig Rosenbaum

Craig Rosenbaum

  • 4,776 Points 4k badge 2x thumb
Is there a way to close two out of three popups on a page?

I tried this but it didn't work:

var pop1 = skuid.$('.ui-dialog-content')[1];
var pop2 = skuid.$('.ui-dialog-content')[2];
pop1.dialog('close');
pop2.dialog('close'); 
Photo of Craig Rosenbaum

Craig Rosenbaum

  • 4,776 Points 4k badge 2x thumb
Figured out a solutions. Not sure if its the best way:

https://api.jqueryui.com/dialog/ helped a lot.
$.each(skuid.$('.ui-dialog-content'), function(i, row){    
    if(i==2 || i==1){
       
        var UIiD = "#"+this.id;
        skuid.$(UIiD).dialog('close');
        
    }
    
});