Skip to content

Instantly share code, notes, and snippets.

@zaynali53
Created April 17, 2022 11:53
Show Gist options
  • Select an option

  • Save zaynali53/e78457613eb98809970af33021570df4 to your computer and use it in GitHub Desktop.

Select an option

Save zaynali53/e78457613eb98809970af33021570df4 to your computer and use it in GitHub Desktop.
Autocomplete
<input id="autocomplete">
const autocomplete = document.querySelector('#autocomplete')
function debounce(callback, delay) {
let timer
return (...args) => {
clearTimeout(timer)
timer = setTimeout(function() {
callback(...args)
}, delay)
}
}
const __e = debounce(function(text) {
console.log(text)
}, 2000)
autocomplete.addEventListener('input', function(event) {
__e(event.target.value)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment