Skip to content

Instantly share code, notes, and snippets.

@aghouseh
Created June 24, 2013 21:49
Show Gist options
  • Save aghouseh/5853925 to your computer and use it in GitHub Desktop.
Save aghouseh/5853925 to your computer and use it in GitHub Desktop.
simple jQuery function to clear a form's elements. differs from a reset in that it will zero values even if they were initially checked / selected on page render.
$.fn.clear = function() {
if (this[0].tagName.toUpperCase() !== 'FORM') { return this; }
return this.find(':input').each(function() {
if (this.type === 'radio' || this.type === 'checkbox') {
this.checked = false;
} else {
$(this).val('');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment