move variable to jquery function

Asked

Viewed 82 times

0

I need to manipulate the button clicked inside this function, how to pass the btn variable inside it?

$('.btn_excluir').on('click', function () {
    btn = $(this);
    swal_confirm('Deseja realmente excluir o registro?', function (btn) {
        console.log(btn);
    });
});
  • 1

    Remove the btn in parentheses. It has already been defined before the function swal_confirm.

1 answer

0

The swal_confirm is not the correct method to use the SweetAlert, according to the documentation you need to perform a function only if the OK button is clicked as in the example below.


Example

swal({
    title: "Deseja deletar?",
    text: "Tem certeza que deseja deletar o registro?",
    icon: "warning",
    buttons: true,
    dangerMode: true,
})
.then((willDelete) => {
    if (willDelete) {
        /* Chama a sua função para deletar */
        swal("Seu registro foi deletado!", {
            icon: "success",
        });
    } else {
        swal("Seu registro não foi deletado!");
    }
});
  • 1

    the swal_confirm method was I who created, and it is working, the problem was just to pass the external button into the swal, and it was solved by taking the variable btn of the parentheses.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.