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

198
Views
How do I apply CSS to this JS Fetch code to alter text position, font?

New to JS. How can I apply CSS to this JS Fetch to alter test position, font? Thank you.

let file = 'art.txt';
    
const handleFetch = () => {
  fetch(file)
    .then((x) => x.text())
    .then((y) => (document.getElementById('kdkz').innerHTML = y));
};

setInterval(() => handleFetch(), 2000);
 <p id="kdkz"></p>
 

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

0

Just add

#kdkz {
  /*styling here*/
}

The browser will apply the styling after fetching.

about 4 years ago · Juan Pablo Isaza Report

0

Modify the handleFetch() to:

const handleFetch = () => {
    fetch(file)
      .then((x) => x.text())
      .then((y) => {
        const target = document.getElementById('kdkz');
        target.innerHTML = y;
        target.style.textAlign = 'center'; // Change the position here.
      });
  };
  

Or, you can easily add style within the HTML document by using <style> tag before the <body>.

<style>
#kdkz {
  text-align: center; /* Change the position here */
}
</style>
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!