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

188
Views
How can I add multiple data to <li>?
function addUserDataToDom(data) {
  const li = document.createElement('li')
  const userList = document.getElementById('user-list')
  const userName = data.items[0].login
  const id = data.items[0].id
  const avatarUrl = data.items[0].avatar_url
  li.innerHTML = userName
}

I have to add my id and avatarUrl to <li> and append to the page? Thank you

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

0

You can add any element to another one with .appendChild( childElement ). So if you want to add the "li" to the body of your document you can do this:

document.body.appendChild( li )

So, in order to achieve what you asked, you should make this:

function addUserDataToDom(data) {

    const li = document.createElement('li')
    const userList = document.getElementById('user-list')
    const userName = data.items[0].login
    const id = data.items[0].id
    const avatarUrl = data.items[0].avatar_url

    // Create p elements to add your user data
    const pUserName = document.createElement("p")
    const pId = document.createElement("p")
    const pAvatrUrl = document.createElement("p")
    
    pUserName.innerText = userName
    pId.innerText = id
    pAvatrUrl.innerText = avatarUrl

    li.appendChild( pUserName )
    li.appendChild( pId )
    li.appendChild( pAvatrUrl )

}

As you can see, all the data was added as innerText inside the p element. Finally you have to append those p elements we created earlier inside your li element.

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!