JSFiddle - React, Tailwind, and code Playground

by David Thomas

HTML

<form action="#" method="post">
    <fieldset>
        <input value="something" />
        <button class="reset">Reset the input</button>
    </fieldset>
    <fieldset>
        <input type="checkbox" name="two"  />
        <input type="checkbox" name="two" checked />
        <input type="checkbox" name="two"  />
        <button class="reset">Reset the input</button>
    </fieldset>
    <fieldset>
        <input type="radio" name="three" checked />
        <input type="radio" name="three" />
        <button class="reset">Reset the input</button>
    </fieldset>
</form>

JavaScript

$('button.reset').click(
    function () {
        $(this).prevAll('input').val(function(){
            switch (this.type){
                case 'text':
                    return this.defaultValue;
                case 'checkbox':
                case 'radio':
                    this.checked = this.defaultChecked;
            }
        });
    });

$('form').submit(

function () {
    return false;
});