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

128
Vistas
Hide div after page reloaded on sweet alert

i'm using sweetalert in ajax post data, and have a div element that i want to hide after page reload, from the code below what i can do to do that :

$(document).ready(function() {
    $(document).on('click', '#approve', function() {
        swal.fire({
            title: 'Are you sure ?',
            icon: 'warning',
            showCancelButton: true,
            confirmButtonText: 'Yes',
            cancelButtonText: 'Cancel',
        }).then((result) => {
            if (result.value) {
                $('.leftForms').each(function(e) {
                    valuesToSend = $(this).serialize();
                    $.ajax($(this).attr('action'), {
                            url: 'data.php',
                            type: 'POST',
                            method: $(this).attr('method'),
                            data: valuesToSend
                        })
                        .done(function(response) {
                            swal.fire({
                                title: 'Data berhasil diupdate!',
                                text: response.message,
                                icon: 'success'
                            }).then(function() {
                                location.reload();
                                localStorage.removeItem('leftcontent');
                                localStorage.getItem('rightcontent', data);
                            });   
                        })
                });
            }
        })
    });
});

i want to hide this, at the moment after location.reload(), is that possible ?

<div id="content1">
<p>blaa..blaa.. bla..</p>
</div>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Why are you reloading the page ? You can hide remove the div using JavaScript instead. Instead of location.reload(); do $("#content1").remove(); to remove the element or $("#content1").hide() to hide it. Also localStorage.removeItem('leftcontent'); and localStorage.getItem('rightcontent', data); isn't being executed.

about 4 years ago · Juan Pablo Isaza Denunciar

0

if you want this choice to actually persist you need to save something to a database for clear reasons, you could use local storage but it will be cleared if the user clears the cache, just save the choice to the local storage then just check for that var when the page reloads and remove the element with:

...
.then(function() {
    localStorage.setItem('choice','hide');
    location.reload();
$(document).ready(function() {
    if(localStorage.getItem('choice')=='hide'){
        $("#content1").remove();
    }
...

but as @Gazmend pointed out you don't even need to reload the page, just remove the element instead of reloading if reloading is not necessary for other reasons

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