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

139
Views
Remove result after submiting in form

I have a simple API that gives you the cover images of shows after submitting a word in a form. I want to clear the search result after the images have been displayed so that the next batch of images show. Is there a way to do this in vanilla Javascript?

const form = document.querySelector('#searchForm');
const input = document.querySelector('#inp');
const btn = document.querySelector('#btn');

form.addEventListener('submit', async function(e)
{
    e.preventDefault();
    console.log(form.elements.query.value);
    const response = await axios.get(`https://api.tvmaze.com/search/shows?q=${input.value}`);
    makeImages(response.data);
    input.value = '';
    const secondResponse = await (btn.addEventListener('click'));
    clearImages(response.data);
    
    
})

const makeImages = (shows) =>
{
    for(let res of shows)
    {
        if(res.show.image){
        const img = document.createElement('IMG');
        img.setAttribute("id","imgAttr");
        img.src = res.show.image.medium;
        document.querySelector('.bd').append(img);
        }
    }
    
}

const clearImages = (shows)=>
{
    for(let res of shows)
    {
        if(res.show.image)
        {
            let imgs = document.querySelector("#imgAttr");
            imgs.parentNode.removeChild(imgs);
        }
    }
}
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!