Created
November 3, 2015 20:06
-
-
Save LindseyWhitney/afdd35c130965131c193 to your computer and use it in GitHub Desktop.
Clears various types of form input.
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
//jQuery Plugin | |
$.fn.clearForm = function() { | |
return this.each(function() { | |
var type = this.type, tag = this.tagName.toLowerCase(); | |
if (tag == 'form') | |
return $(':input',this).clearForm(); | |
if (type == 'text' || type == 'password' || tag == 'textarea') | |
this.value = ''; | |
else if (type == 'checkbox' || type == 'radio') | |
this.checked = false; | |
else if (tag == 'select') | |
this.selectedIndex = -1; | |
}); | |
}; | |
// Call it on your <form> | |
$('form').clearForm(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code snippets found on jQuery Howto:
http://jquery-howto.blogspot.com/2013/08/jquery-form-reset.html