When setting an input element's type to hidden
, and it's value to an empty string, it seems to revert to a previous non-empty value. Can someone please explain why the input value reverts in console log instances 2 and 6 below?
var el = document.getElementById('input');
el.type = 'text';
el.value = '';
console.log('1', el.value);
el.type = 'hidden';
console.log('2', el.value);
el.type = 'text';
el.value = 'hello';
console.log('3', el.value);
el.type = 'hidden';
console.log('4', el.value);
el.type = 'text';
el.value = '';
console.log('5', el.value);
el.type = 'hidden';
console.log('6', el.value);
<input id="input" type="hidden" value="test">