the code I see here and the related SO questions seem incomplete.
Resetting the form means setting the initial values from HTML, so I put it together for a small project that I did based on the code above:
$(':input', this) .not(':button, :submit, :reset, :hidden') .each(function(i,e) { $(e).val($(e).attr('value') || '') .prop('checked', false) .prop('selected', false) }) $('option[selected]', this).prop('selected', true) $('input[checked]', this).prop('checked', true) $('textarea', this).each(function(i,e) { $(e).val($(e).html()) })
Please let me know if I miss something or something else can be improved.
source share