Retrieving item in another function with jquery / js

1

How can I save an item via jquery to be used later?

I have the following structure, where I retrieve the item from an onclick event of a button, retrieve the row of the table to which that button is associated, and display the information for that row with a modal

RemoveTableRow = function(item) {   

     var Linha = $(item).closest('tr');

     var Codigo   = $(Linha).find('td[data-codigo]').data('codigo');

     AbreModal('Deseja realmente excluir esse Contato?');

    return false;         
}

Then when the user clicks on the delete button belonging to modal, to remove the row from the table would like to recover this item to be able to perform the fact function to delete:

var tr = $(item).closest('tr'); 

tr.fadeOut(400, function() {              
    tr.remove();            
}); 
    
asked by anonymous 28.12.2017 / 15:06

1 answer

3

How are you capturing that code in the RemoveTableRow function in:

var Codigo   = $(Linha).find('td[data-codigo]').data('codigo');

You can send this code in the AbreModal function as a second parameter:

AbreModal('Deseja realmente excluir esse Contato?', Codigo);

And include in the modal button the code passed in the function. Something like:

function AbreModal(mensagem, codigo){
   // exibe a modal com os parâmetros "mensagem" e "codigo"
}
    
28.12.2017 / 18:09