Skip to content

Instantly share code, notes, and snippets.

@ABM-Dan
Created August 25, 2016 17:14
Show Gist options
  • Save ABM-Dan/e1ab4aca1e4cfe5809e1cd3a672f740f to your computer and use it in GitHub Desktop.
Save ABM-Dan/e1ab4aca1e4cfe5809e1cd3a672f740f to your computer and use it in GitHub Desktop.
(function($) {
return $.fn.resetInput = function(callback) {
return this.each(function() {
var $el, type;
$el = $(this);
type = this.type;
switch (type) {
case 'select-one':
case 'select-multiple':
$el.find('option').each(function() {
return this.selected = this.defaultSelected;
});
break;
case 'checkbox':
case 'radio':
this.checked = this.defaultChecked;
break;
default:
this.value = this.defaultValue;
}
if (typeof callback === 'function') {
return callback.call(this);
}
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment