Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!