How to convert this div to input

<div id="test">test</div>

I want to convert to

<input id="test" value="test"/>

el = document.getElementById ("test");
el.setAttribute ("value", "test");

but how does div become input?

Apr.01,2022

create input and delete div;

var div = document.getElementById('test');
var ipt = document.createElement('input');
ipt.setAttribute('id','test');
ipt.setAttribute('value',div.innerText);
document.body.appendChild(ipt);
div.remove();
Menu