If you have a form, just add input with type reset
<input type="reset" value="Clear the Form" />
If you cannot use this, save the defaults with .data and extract them to you reset in the form.
See this example in jsFiddle
$("#container :text").each(function() { var $this = $(this); $this.data("default", $this.val()); }); $("#container select option").each(function() { var $this = $(this); $this.data("default", $this.is(":selected")); }); $("#container :button").click(function() { $("#container :text").each(function() { var $this = $(this); $this.val($this.data("default")); }); $("#container select option").each(function() { var $this = $(this); $this.attr("selected", $this.data("default")); }); });
HTML
<div id="container"> <input type="text" value="default" /> <select> <option>Op1</option> <option selected="true">Op2</option> </select> <select multiple="true" size="5"> <option>Op1</option> <option selected="true">Op2</option> </select> <input type="button" value="reset" /> </div>
To clear all inputs and remove all parameters on select elements, it is simpler, see this example in jsFiddle (same html).
$("#container :button").click(function() { $("#container :text").val(""); $("#container select").empty(); });
source share