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

197
Views
Why can't i append my div to another div?

i'm trying to display my picture to my gallery div but the console shows the mistake as "uncaught (in promise) TypeError: document.getElementsByClassName(...).appendChild is not a function". I don't know what's wrong, please help me! Thank you so much!

const auth = "563492ad6f917000010000018130a0db31044cd6b83e19c30395d9e1"
const input = document.querySelector("input")
const nextBtn = document.getElementsByClassName("next")
const gallery = document.getElementsByClassName("gallery")
const searchBar = document.getElementsByClassName("searchBar")

let pageOne = 1;
let search = false;
let query = "";

input.addEventListener("input", (e) => {
  e.preventDefault()
  query = e.target.value

})

async function createPhotos(pageOne) {
  const data = await fetch("https://api.pexels.com/v1/curated?per_page=${pageOne}", {
    method: "GET",
    headers: {
      Accept: "application.json",
      Authorization: auth
    }
  })
  
  const result = await data.json()
  
  result.photos.forEach((photo) => {
    const pic = document.createElement("div")
    pic.innerHTML = `<img src=${photo.src.large}/ >`
    document.getElementsByClassName("gallery").appendChild(pic)
  })
}
createPhotos(pageOne)
<div class="container">
  <div class="searchBar">
    <input type="text" />
    <button type="button">Search</button>
  </div>
  <div class="gallery"></div>
  <div class='next'>Next Page</div>
</div>

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!