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

150
Vistas
Javascript: console.logs in function to html div as function executes

I want to show console log in html div. I am able to do that with below code.

var log = document.getElementById("logger")
 console.log = (function (method, log) {
        return function (text) {
            method(text);
            let msg = document.createElement('div');
            msg.textContent = text;
            log.appendChild(msg);
        };
 })(console.log.bind(console), log);

But console.log in functions does show in html div unless whole function execution is complete?

How can I show console logs in html div as function is executing (without waiting for function to complete its execution)?

In below example, I see logs in div after for loop execution gets complete.

function testfunction(){
    console.log('test function');
    for(let i=0; i<100000; i++){
        console.log(i);
    }
} 

I see updated logs in div in Inspect-> Elements and not on browser page.

enter image description here

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

0

give it some time to execute otherwise everything will be processed at the same time

function testfunction(){
    console.log('test function');
    for(let i=0; i<100000; i++){
        setTimeout(() => {
           console.log(i);
        }, i * 5)
    }
} 
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