Created
June 24, 2013 21:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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