Skip to content

Instantly share code, notes, and snippets.

@kinopyo
Created June 25, 2012 10:56
Show Gist options
  • Save kinopyo/2987947 to your computer and use it in GitHub Desktop.
Save kinopyo/2987947 to your computer and use it in GitHub Desktop.
jQuery: disables button and swaps text to loading text.
// disables button and swaps text to loading text
$.fn.setLoadingState = function (loadingText) {
if (!loadingText) {
loadingText = 'Loading...'
}
$(this).prop('disabled', true).val(loadingText);
// allow jQuery chaining
return this;
};
// Usage
$('#some_button').setLoadingState();
$('#some_button').setLoadingState('Please wait...');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment