2
I’m trying to transform the status of the table into a tag, I got it with jQuery but it’s only applying in the first row of the table (generated with PHP), the rest the text is not replaced.
PHP
<?php foreach ($users as $user): ?>
<tr>
<th scope="row"><?=$user->id_matricula?></th>
<td><?=$user->nm_usuario?></td>
<td><?=$user->nm_setor?></td>
<td><?=$user->nm_cargo?></td>
<td><?=$user->ds_login?></td>
<td><?=$user->ds_perfil?></td>
<td><?=$user->dt_create?></td>
<td><?=$user->dt_update?></td>
<td class="text-center" id="status"><?=$user->ds_status?></td>
</tr>
<?php endforeach?>
jQuery
$(function () {
var op = $("#status").text();
switch (op) {
case 'Ativo':
$("#status").html('<i class="fas fa-circle fa-small-size text-success"></i>');
break;
case 'Inativo':
$("#status").html('<i class="fas fa-circle fa-small-size text-warning"></i>');
break;
case 'Bloqueado':
$("#status").html('<i class="fas fa-circle fa-small-size text-danger"></i>');
break;
default:
break;
}
});
Thanks for the guidance, it worked perfectly.
– Estênio