Triggering callback after user stops typing jQuery

The snippet below triggers a callback when user stops typing on the input field. The process gets repeated everytime. This is a useful piece of snippet which can be used to trigger a custom callback function such as auto save or spelling checker etc.
JQUERY
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
var x_timer; $("#input-box").keyup(function (e){ clearTimeout(x_timer); var user_name = $(this).val(); x_timer = setTimeout(function(){ // callback_function(); console.log("user stopped"); }, 1000); });
HTML
  • 1
<textarea id="input-box"></textarea>
You should see a text on your js console "user stopped" everytime you stop typing.
    New question is currently disabled!