-2
I would like some help with these functions. I would like the last td to change every time it is clicked between active and inactive. But it only works the first time clicked after it doesn’t work anymore. Can anyone help me? Follow code example below.
Thank you.
$(document).ready(function(){
$('#tabela tbody tr').each(function(i, linha) {
$(this).find('a[name=botaoAtivo]').click(function() {
var teste = $(linha).find('td:eq(4)');
console.log('Teste: ' + teste);
teste.html("<a name='botaoInativo' href ='#'><span class='badge badge-danger'>Inativo</span></a>");
});
$(this).find('a[name=botaoInativo]').click(function() {
var teste2 = $(linha).find('td:eq(4)');
console.log('Teste2: ' + teste2);
teste2.html("<a name= 'botaoAtivo' href ='#'><span class='badge badge-success'>Ativo</span></a>");
});
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id = "tabela">
<thead>
<tr>
<th>#</th>
<th>Fantasia</th>
<th>Cidade</th>
<th>Email</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Cliente1</td>
<td>Santa Cruz do Sul/RS</td>
<td>[email protected]</td>
<td><a name= "botaoAtivo" href ="#">Ativo</a></td>
</tr>
<tr>
<td>2</td>
<td>Cliente2</td>
<td>Santa Cruz do Sul/RS</td>
<td>[email protected]</td>
<td><a name="botaoInativo" href ="#">Inativo</a></td>
</tr>
It Worked So Thank You Very Much!
– Lucas Machado