Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Live Feedback (debounced)</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style>#status{font-size:13px;margin-top:4px;}</style> </head> <body> <label>Username (3+):</label><br> <input id="user"> <div id="status"></div> <script> var t=null; $("#user").on("input", function(){ clearTimeout(t); var v = this.value; t = setTimeout(function(){ $("#status").text(v.length>=3 ? "Looks good ✓" : "Too short"); }, 250); }); </script> </body> </html>
Output