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

496
Views
¿Cómo hacer la paginación (número del elemento actual)?

Quiero hacer una navegación, que se vea como 1/5, luego 2/5, luego 3/5 y así sucesivamente.

  • el primer dígito es el número de la página actual
  • el segundo dígito es el número total de páginas

Por el momento, todo funciona, excepto el número de la página actual: se crea, pero la anterior no se elimina.

¡Gracias de antemano!

 // slides let item = document.querySelectorAll('.item'); let btn = document.querySelector('.btn'); let el_active; let current = document.querySelector('.current'); let total = document.querySelector('.total'); function navigate() { for (let i = 0, length = item.length; i < length; i++) { if (item[i].classList.contains('active')) { el_active = i; current.append(i + 2); break; } } item.forEach(function(tab) { tab.classList.remove('active'); }); if ((el_active + 1) === item.length) { item[0].classList.add('active'); } else { item[el_active + 1].classList.add('active'); } } btn.addEventListener('click', function() { navigate(); sliceAll() }); let all = item.length; total.append(all);
 .item { display: none; } .item.active { display: block; }
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div class="items"> <div class="item active">111</div> <div class="item">222</div> <div class="item">333</div> <div class="item">444</div> <div class="item">555</div> </div> <br> <div class="nav"> <span class="current">1</span> / <span class="total"></span> </div> <br> <button class="btn" type="button">Next</button> </body> </html>

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

0

Debe usar textContent en lugar de append , ya que append agregará pero no restablecerá el valor anterior.

 // slides let item = document.querySelectorAll('.item'); let btn = document.querySelector('.btn'); let el_active; let current = document.querySelector('.current'); let total = document.querySelector('.total'); function navigate() { for (let i = 0, length = item.length; i < length; i++) { if (item[i].classList.contains('active')) { el_active = i; current.textContent = (i + 2); break; } } item.forEach(function(tab) { tab.classList.remove('active'); }); if ((el_active + 1) === item.length) { item[0].classList.add('active'); } else { item[el_active + 1].classList.add('active'); } } btn.addEventListener('click', function() { navigate(); sliceAll() }); let all = item.length; total.append(all);
 .item { display: none; } .item.active { display: block; }
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div class="items"> <div class="item active">111</div> <div class="item">222</div> <div class="item">333</div> <div class="item">444</div> <div class="item">555</div> </div> <br> <div class="nav"> <span class="current">1</span> / <span class="total"></span> </div> <br> <button class="btn" type="button">Next</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!