Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
How can I make a previously incremented set of numbers appear below the current numbers in a new line?

I wrote a javascript that increases a set of numbers every second, where every increased set writes on a new line separated by a horizontal rule. E.g;

20220215155

20220215156

20220215157

20220215158 etc...

var i = 20220215155;
    function increment(){
     i++;
        document.getElementById('period').innerHTML += i + "<br />" + "<hr />" ;
    }
    setInterval('increment()', 1000);

But I want every current set of the numbers to always be in the first line, whereby a previously increased set goes below the currently increased set... E.g;

20220215159

20220215158

20220215157

20220215156

20220215155

Please how do I go about this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Like this?

<button id="start">Start Incrementing</button>
<button id="stop">Stop Incrementing</button>
<div id="main"></div>

<script>
    const main = document.querySelector('#main');
    const startBtn = document.querySelector('#start');
    const stopBtn = document.querySelector('#stop');
    let i = 0;
    let interval = null;

    const createElem = () => {
        const div = document.createElement('p');
        div.className = 'inc-elem';
        const h1 = document.createElement('h1');
        h1.innerText = i;
        const hr = document.createElement('hr');

        div.appendChild(h1);
        div.appendChild(hr);
        return div;
    };

    window.addEventListener('DOMContentLoaded', () => {
        const startingDiv = createElem();
        main.prepend(startingDiv);
    });

    const increment = () => {
        i++;
        const newDiv = createElem();
        main.prepend(newDiv);
    };

    startBtn.addEventListener('click', () => (interval = setInterval(increment, 1000)));
    stopBtn.addEventListener('click', () => clearInterval(interval));
</script>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda