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

151
Views
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 answers
Answer question

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 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!