Modal window does not work correctly when you click YES

0

I'm having some trouble with the following Jquery code:

JQUERY

$(document).ready(function(){
     $('#modalLogout').click(function(){
          $('#yes').click(function(){

              function time()
              {
                 $(location).attr('href',"destroy.php");
              }

              /*set 1s after ckick in yes, after that redirect to index*/           
              setTimeout(function(){time()},1000);
              /*table fadeout effect*/  
              $(".row").hide("slow");
        }); 
     });
});

What happens is that when opening a modal confirmation window if you are sure if you want to continue or end the session, when I click YES it does nothing the first time, I have to reopen the window and YES to the time () function to be executed. Already when I click on NO it works correctly, that is, it closes the window and remains in the session started. How could I change this strange behavior and improve the code?

    
asked by anonymous 24.07.2015 / 21:27

2 answers

4

You only define what needs to be done on the YES click when you click on #modalLogout . I did not quite understand the intention of this "outside" part of the code, it would seem that I would simply set the YES click separately:

$(document).ready(function(){
     $('#yes').click(function(){

          function time()
          {
             $(location).attr('href',"destroy.php");
          }

          /*set 1s after ckick in yes, after that redirect to index*/           
          setTimeout(time, 1000);
          /*table fadeout effect*/  
          $(".row").hide("slow");
    }); 
});

Notice that I also simplified your call to setTimeout .

    
24.07.2015 / 21:30
1

If your intention was to assign the click event to the #yes child element of the #modalLogout element then the change that should be made to your code is as follows:

function time() {
    $(location).attr('href',"destroy.php");
}

$(document).ready(function() {
    $('#modalLogout #yes').click(function(){         
        setTimeout(time, 1000);

        $(".row").hide("slow");
    });
});
    
24.07.2015 / 22:27