How to make a div become an input on click?
-
It is necessary that by clicking on the div, it becomes an input with the text that was previously in the divJavaScript Hazel Hancock, Aug 5, 2019
-
Hide the diva, show the input with the techst which was in the diva
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="div">
это текст щас будет в input
</div>
<input id ='input' hidden="true">
<script>
let div=document.getElementById('div');
let input=document.getElementById('input');
div.onmousedown=()=>{
div.hidden=true;
input.hidden=false;
input.value=div.innerText;
input.style.width='100%'
}
</script>
</body>
</html>Anonymous -
let div = document.querySelector('div');
div.addEventListener('click', function () {
document.body.removeChild(div);
let input = document.createElement('input');
document.body.append(input);
input.value = 'some text';
})
that's how you canAnonymous
2 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!