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

184
Views
how to run onclick function with the dynamic string?

I am trying to get ID from an API (ID: food.slug) now as the value of the ID is string I am getting an error. index.html:1 Uncaught ReferenceError: apple_iphone_13_pro_max is not defined at HTMLButtonElement.onclick

This is the code

const showitem = (foods) => {
    const parent = document.getElementById('parent');
    for (const food of foods) {

        const newdiv = document.createElement('div');
        newdiv.classList.add('col')
        newdiv.innerHTML = `
      
        <div class="card" >
            <img src="${food.image}" class="card-img-top" alt="...">
            <div class="card-body">
                <h5 class="card-title">Card title</h5>
                <p class="card-text">This is a longer card with supporting text below as a natural lead-in to
                    additional content. This content is a little bit longer.</p>
            </div>

            <button onclick="singleitem(${food.slug})">details</button>
        </div>`;
        console.log(food.slug);

        parent.appendChild(newdiv);

   }
}
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!