Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
How can I filter API through clicking on HTML li?

So I have a Google Books API for searching books. I have a searchBar which allows to search books writing any information about them and pass it to function as query:

function searchBook(query){
        const url = BASE_URL + `${query}` + '&' + API_KEY;
    
        fetch(url)
        .then(res => res.json())
        .then(books => showBooks(books.items));
    }

But now I want to make a ul which displays different categories of books, and when I click on one of the li, it displays books of this certain category. Picture with categories ul:

enter image description here

Javascript code for selecting categories when clicking on li:

const list = document.getElementById('list');

        const li = list.querySelectorAll('li');

        for (let i = 0; i < li.length; i++) {
            li[i].addEventListener("click", e =>{
                e.target.innerHTML == "Fiction" ? searchBook('subject:fiction') : console.log('doesnt work');
            })
            
        }

But for some reason nothing happens, books don't display and the console is empty, and there's no errors either.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda