JSFiddle - React, Tailwind, and code Playground

HTML

<form>
    <input type="text" value="A text box" /><br />
    <textarea>Some text</textarea><br />
    <select>
        <option>This is an option</option>
        <option>So is this</option>
        <option>And this</option>
    </select>
    <div>
        <input id="butt" type="button" value="Test" />
    </div>
</form>

JavaScript

var getHTML = function() {
    $('form input').each(function() {
        this.setAttribute('value', this.value);
        if (this.checked) this.setAttribute('checked', 'checked');
        else this.removeAttribute('checked');
    });

    $('form select').each(function() {
        var index = this.selectedIndex;
        var i = 0;
        $(this).children('option').each(function() {
            if (i++ != index) this.removeAttribute('selected');
            else this.setAttribute('selected', 'selected');
        });
    });

    $('form textarea').each(function() {
        $(this).html($(this).val());
    });
    alert($('form').html());
    return $('form').html();
};
document.getElementById('butt').onclick = getHTML;