How to make a div become an input on click?

  • 0
    It is necessary that by clicking on the div, it becomes an input with the text that was previously in the div
    JavaScript Hazel Hancock, Aug 5, 2019

  • 2 Answers
  • 0
    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

  • 0
    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 can
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!