JSFiddle - React, Tailwind, and code Playground
by Chris Rebert
HTML
<input type="text" value="AAA" id="q">
JavaScript
var input = document.getElementById('q');
input.value = "BBB";
input.type = "file";
input.type = "text";
// Per https://html.spec.whatwg.org/multipage/forms.html#text-(type=text)-state-and-search-state-(type=search):dom-input-value-value ,
// type="text" changes the mode (https://html.spec.whatwg.org/multipage/forms.html#dom-input-value-value ) // from "filename" to "value".
//
// Per Step 2 of https://html.spec.whatwg.org/multipage/forms.html#input-type-change :
// "then set the value of the element to the value of the value content attribute, if there is one, or the empty string otherwise"
alert("The value property (" + JSON.stringify(input.value) + ") should equal the value attribute (" + JSON.stringify(input.getAttribute('value')) + ")");