ignore if confirm is canceled

1

I want that when you click on cancel, do not redirect to the url of the link, how to do it?

$('#concederRol').click(function() {
                      confirm("esta seguro de realizar esta accion? esta accion es irrevocable"); 
                   });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="www.google.com" id="concederRol"> enviar
    
asked by hubman 14.04.2017 в 23:09
source

1 answer

3

The confirm method will return a booleando value depending on the option that is selected , for this case if cancelar is selected then it will return false , in the if we verify this with !x , if so we return false so that the re address is not executed.

$('#concederRol').click(function() {
    var x = confirm("esta seguro de realizar esta accion? esta accion es irrevocable"); 
    if(!x)return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="www.google.com" id="concederRol"> enviar
    
answered by 14.04.2017 / 23:10
source