I use for my current online store, the search of Algolia. I would like to extend this search with the function that when customers press the Enter key, the click on the button "Show all results" is triggered.
My problem is that I constantly get the error message (
index):TypeError: input.addEventListener is not a
function
in the devtools and I slowly do not know why. Anyone have an idea how I can trigger this click event?
HTML Input
<input class="ais-SearchBox-input" type="search" placeholder="" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" maxlength="512">
HTML Button
<a class="search-query-route cta-button w-inline-block" id="milo" style="margin-top:-20px" href="">Alle Ergebnisse anzeigen</a>
Script
var input = document.getElementsByClassName(".");
input.addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
document.getElementById("milo").click();
}
});
Source: Ask Javascript Questions