Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

384
Visualizações
Why does JQuery closest().remove() is not working?

I'm trying to remove row after successful ajax call. Ajax works like intended, but its success function doesn't work. I searched other similar questions, but couldn't find solution for my problem. I tried debugging it checking if $(this).closest("tr") is set properly but, I only managed to check that it's not null. I'm not sure if the error is in closest() or remove().

HTML:

                        <tbody id="userlist">
                            @foreach ($users_with_permission as $user)
                                <tr>                                      
                                    <td><span>{{ $user['name'] . ' ' . $user['surname'] . '-[' . $user['companies']['name'] . ']-[' . $user['branches']['name'] . ']-[' . $user['departments']['name'] . ']' }} </span></td>
                                    <td>
                                        <form class="removeUserPermission">
                                            <input type="hidden" name="id" value="{{ $user['id'] }}">
                                            @foreach ($selected_permissions as $permission)
                                                <input type="hidden" name="permissions[]"  value="{{ $permission }}">
                                            @endforeach
                                            <button class="btn btn-danger" type="submit">X</button>
                                        </form>
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>

JS:

$('#userlist').on('submit','.removeUserPermission' ,function(e) {
            e.preventDefault();
            $.ajax({
                type: "post",
                url: "{{ route('role.revokePermission') }}",
                data: $(this).serialize(),
                success: function(response) {
                    $(this).closest("tr").remove();     
                }

            });
        });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try the below code

$('#userlist').on('submit','.removeUserPermission' ,function(e) {
            e.preventDefault();
            var ths = $(this);
            $.ajax({
                type: "post",
                url: "{{ route('role.revokePermission') }}",
                data: $(this).serialize(),
                success: function(response) {
                    ths.parent('tr').remove();     
                }

            });
        });
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda