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

74
Views
I am trying to increment when increment button is pressed but I am getting [object HTMLParagraphElement]1

I am working on this increment function when the increment button is pressed that should add +1 to count element. This is my html:

<p id="count-el">0</p>
<button id="increment-btn" onclick="increment()">INCREMENT</button>

JS:

let countEl = document.getElementById('count-el');

function increment() {
  countEl.textContent = countEl + 1;
}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You need to create a variable and then increment that variable in your increment function.

let count = 0;
let countEl = document.getElementById('count-el');
countEl.textContent = count;

function increment() {
  count++;
  countEl.textContent = count;
}

about 4 years ago · Juan Pablo Isaza Report

0

You can either use a 'count' variable to maintain count and display it after every increment. Or parse the number in the inner text to int and add.

This should work:

let countEl = document.getElementById('count-el');

function increment() {
    countEl.textContent = parseInt(countEl.innerHTML) + 1;
}
about 4 years ago · Juan Pablo Isaza Report

0

Try this

let countEl = document.getElementById('count-el');
let count = 0;
function increment() {
  count++;
  countEl.textContent = count;
}
function decrement() {
  count--;
  countEl.textContent = count;
}
 <p id="count-el">0</p>
 <button id="increment-btn" onclick="increment()">INCREMENT</button>
 <button id="increment-btn" onclick="decrement()">DECREMENT</button>

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!