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

126
Visualizações
javascript refresh page but keep DOM elements created

I have a project, but for it to work I need to refresh the page every time I create a new element. The problem is that when I refresh the page it also deletes the created dom elements. Is there a way to reload everything but keep the dom elements until you refresh te page yourself?

    function BTN() {
        for (let i = 0; i < 7; i++) {
            let btn = document.createElement('button');
            btn.classList.add('btn')
            btn.id = 'Button' + i
            btn.innerHTML = 'Button' + i;

            document.getElementsByClassName('Btns')[0].appendChild(btn);
        }
    }

    document.getElementsByClassName('QPB')[0].addEventListener('click', () => {
        BTN()
    })
    .btn {
        width: 100px;
        height: 50px;
        background-color: red;
        margin-right: 10px;
    }

    .QPB {
        width: 50px;
        height: 50px;
        margin-bottom: 10px;
        background-color: orange;
    }
<Button class="QPB">+</Button>
<div class="Btns">

</div>

So I need to refresh the page but not delete all elements. Is there a way to do it?

about 4 years ago · Juan Pablo Isaza
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