let timeout = null$("#text-input").on('input', function() { const val = $(this).val() let delay = 300 const len = val.length if (len == 0) { return } else if (len == 1) { delay = 1000 } else if (len <= 3) { delay = 700 } else if (len <= 5) { delay = 500 } clearTimeout(timeout) timeout = setTimeout(() => { // do something }, delay)})
❤️ Is this article helpful?
Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.
Do send some 💖 to @d_luaz or share this article.
✨ By Desmond Lua
A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz
👶 Apps I built
Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.