Check if Popup is open then close it

Check if Popup is open then close it

I am using Jquery Mobile for my Applicaion .
In my page i have 5 popups as shown above 


  1.     <div data-role="popup" id="one"    class="ui-content" data-theme="a">
  2.         </div>
  3.     
  4.     <div data-role="popup" id="two"    class="ui-content" data-theme="a">
  5.         </div>
  6.     
  7.     <div data-role="popup" id="three"    class="ui-content" data-theme="a">
  8.         </div>


My requirement is that , 
On click of the device backup button , how can i check if any of the popup is open , close it 


I have tried this code , but its not working 

  1.     function homedeliverypagebackfunctionality() {
  2.     
  3.       if($("#one").hasClass("ui-popup-active"))
  4.     {
  5.     $( "#one" ).popup( "close" );
  6.     }
  7.     
  8.     if($("#two").hasClass("ui-popup-active"))
  9.     {
  10.     $( "#two" ).popup( "close" );
  11.     }
  12.     
  13.     if($("#three").hasClass("ui-popup-active"))
  14.     {
  15.     $( "#three" ).popup( "close" );
  16.     }
  17.     
  18.     
  19.     }