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

117
Vistas
How to trigger search on enter key and button click javascript?

I want to trigger the search button to work when the "search" button is clicked and when the enter key on the keyboard is pushed. So far, the search works when the button is clicked. How do I add that to this code?

Thanks!

//Search button click
document.getElementById("search").addEventListener("click", () => {
    //initializations 
    let searchInput = document.getElementById("search-input").value;
    let elements = document.querySelectorAll(".question-name");
    let cards = document.querySelectorAll(".card");



    //loop through all elements 
    elements.forEach((element,index) =>{
        //check if text includes  the search value
        if(element.innerText.includes(searchInput.toString())){
            //display matching card
            cards[index].classList.remove("hide");
        }
        else {
            //hide others 
            cards[index].classList.add("hide");
        }

    })
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

document.getElementById('search').addEventListener('keyup',function(e) {
 if(e.code==13) {/*your code goes here*/}
  })

More informations: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code

about 4 years ago · Juan Pablo Isaza Denunciar
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