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

293
Views
Jquery.text() have changed but text in <div> not change in recursive function

I have a recursive Function to read data and have some code Jquery in that function. My data:

const data = {
    name: "Quotes"
    children: [
        { 
             name: "Quotes/Quote - Quote 1 - 1",
             children: [],
             ....
        }, 
        { 
             name: "Quotes/Quote",
             children: [{..}, {...}, ...],
             ....
        },
        { 
             name: "Body",
             children: [{..}],
             ....
        },
        ...
    ],
    .....
}

My Code:

// index.html
<div id="label">Start parse data ...</div>

// index.js
function parseData(data) {
     $('#label').text(data.name);
     console.log(data.name);  //  I put console to track data

     ...... // my code to process
     
     if (data.children.length) {
          for (const childrenData of data.children) {
               parseData(childrenData);
          }
     }
    
     
}

const data = $.ajax(.....)  // data return from ajax is above,

parseData(data);

$('#label').text("==== Done ====");

The result, my text is "Start parse data ...", after few second, it change to "==== Done ====". My expectation is it change to data.name during parseData().

I have track my recursive function by console.log() and data is working fine. enter image description here

I have searched on Internet and somebody said that put into setTimeout(), but it is NOT still working

setTimeout(() => $('#label').text(data.name), 0);
about 4 years ago · Juan Pablo Isaza
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!