Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

380
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda