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

96
Views
Update DOM of popup.html after clicking button

I am making a chrome extension. I want to update a h3 element in popup.html with some text after click a submit button with id submit.

<!-- popup.html -->
<div class="row">
  <h3 id="status"></h3>
</div>
// popup.js
function saveClass() {
    var status = document.getElementById('status')
    status.innerText = 'success';
}

document.getElementById("submit").addEventListener("click", saveClass);

The function populates the element with the text, and I see the text, but it disappears immediately, within some microseconds. Where I am going wrong ?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

For me its' working fine. You can refer the following code snippet

<html>

<body>
    <!-- popup.html -->
    <div class="row">
        <h3 id="status"></h3>
    </div>
    <button id="submit">Submit</button>
    <!-- popup.js -->
    <script>
    
        function saveClass() {
            var status = document.getElementById('status')
            status.innerText = 'success';
        }
        document.getElementById("submit").addEventListener("click", saveClass);
    </script>
</body>

</html>
about 4 years ago · Juan Pablo Isaza Report

0

The form refreshes the page by default upon submission, due to which the populated text vanishes. Just add an event listener to disable it, which keeps the DOM intact.

var form = document.getElementById("myForm");
function handleForm(event) { event.preventDefault(); } 
form.addEventListener('submit', handleForm);
about 4 years ago · Juan Pablo Isaza Report
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!