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

153
Views
How to display / render data from fetched api with the help of async await

I have one function in which I get data from the API and parsing it to json.

In the second function, I try to insert data into a DOM element.

Where is the problem, please, and how do we render this data correctly?

Firt function:

// GET PUBLIC IP
const getIp = async () => {

    const reqIp = await fetch("https://ipinfo.io/json?token=xxx")
    return reqIp.json()

}

Second function:

document.addEventListener("DOMContentLoaded", async () => {
    const dataIp = await getIp()
    let ipAdress = document.querySelectorAll('.ip p')
    ipAdress.innerHTML = dataIp.ip
})

getIp()

DOM:

<div class="ip">
  <h5>Your IP Adress:</h5>
  <p></p>
</div>

The token is OK, the data is displayed correctly in the console.

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

0

Ohh, too much redbull and too little sleep.

Thank you very much guys.

As they wrote in the comments, the problem was in the selector.

document.addEventListener("DOMContentLoaded", async () => {
    const dataIp = await getIp()
    let ipAdress = document.querySelector('.ip p')
    ipAdress.innerHTML = dataIp.ip
})

getIp()

This is how it works without problems

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!