let searchInput = document.getElementById('booksearch'); let timeout = null; // Listen for keystroke events searchInput.addEventListener('keyup', function (e) { // Clear the timeout if it has already been set. clearTimeout(timeout); // Make a new timeout set to go off in 1000ms (1 second) timeout = setTimeout(function () { if (searchInput.value.length > 2) { searchTags(searchInput.value); } else { clearSearchTags(); } }, 1000); }); function searchTags(searchInput) { console.log(searchInput); } function clearSearchTags() { console.log("stop search"); }