Quiero activar el botón de búsqueda para que funcione cuando se hace clic en el botón "buscar" y cuando se presiona la tecla Intro en el teclado. Hasta ahora, la búsqueda funciona cuando se hace clic en el botón. ¿Cómo agrego eso a este código?
¡Gracias!
//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"); } }) });document.getElementById('search').addEventListener('keyup',function(e) { if(e.code==13) {/*your code goes here*/} })Más información: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code