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

127
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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