Clear form fields with jQuery Clear form fields with jQuery jquery jquery

Clear form fields with jQuery


For jQuery 1.6+:

$(':input','#myform')  .not(':button, :submit, :reset, :hidden')  .val('')  .prop('checked', false)  .prop('selected', false);

For jQuery < 1.6:

$(':input','#myform')  .not(':button, :submit, :reset, :hidden')  .val('')  .removeAttr('checked')  .removeAttr('selected');

Please see this post: Resetting a multi-stage form with jQuery

Or

$('#myform')[0].reset();

As jQuery suggests:

To retrieve and change DOM properties such as the checked, selected, or disabled state of form elements, use the .prop() method.


$(".reset").click(function() {    $(this).closest('form').find("input[type=text], textarea").val("");});


Any reason this shouldn't be used?

$("#form").trigger('reset');