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

183
Views
How do I have a number update and display live in HTML consecutively?

So far I'm stuck here. I continue to get NAN as a result. I tried by starting off with a paragraph and fetching number 0 but returns "cannot read properties of null (reading 'addEventListener')"

<html>
<style>
</style>
<body>
 <p id="result" value=0>
      0
 </p>
 <button id="func">RUN IT</button>
 <script> 
document.getElementById("func").addEventListener("click", () => {
 var n = document.getElementById("result");
 console.log(result);
 if (n != 10) {
      n++;
      
document.getElementById("result").innerHtml = n;
 }});
</script>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

If I understand your problem correctly, you want to add 10 to the result every time the button is clicked.

  let result = document.querySelector('#result');
        document.querySelector('#func').addEventListener('click', (e) => {
            if (result.textContent != 10) {
                result.textContent++
            }
        })
<p id="result">0</p>
    <button id="func">RUN IT</button>

I hope I could have helped

about 4 years ago · Juan Pablo Isaza Report

0

document.getElementById("func").addEventListener("click", () => {
  var n_isADomElement = document.getElementById("result");
  let v = +n_isADomElement.innerText
  
  if (v != 10) {
    v++;
    n_isADomElement.innerText = v;
  }
  
});
<html>
<style>

</style>

<body>
  <p id="result" value=0>
    0
  </p>
  <button id="func">RUN IT</button>
</body>

</html>

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!