Skip to content

Instantly share code, notes, and snippets.

@raddevon
Created June 7, 2013 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raddevon/5729678 to your computer and use it in GitHub Desktop.
Save raddevon/5729678 to your computer and use it in GitHub Desktop.
Bind form input value change with a delay
// Bind input change with a delay
$(document).on('input propertychange', 'textarea', function () { // Change 'textarea' to desired element
var detailsElement = $(this),
details = $(this).val();
// If it's the propertychange event, make sure it's the value that changed.
if (window.event && event.type == 'propertychange' && event.propertyName != 'value')
return;
// Clear any previously set timer before setting a fresh one
window.clearTimeout($(this).data('timeout'));
$(this).data('timeout', setTimeout(function () {
// Do your thing here
}, 5000)); // Change delay as desired. 5000 = 5s
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment