JSFiddle - React, Tailwind, and code Playground

by Bacher

HTML

<div class="normal">
    <input class="i1"/>
</div>
<div class="hidden-bag">TT</div>

CSS

.hidden-bag {
    /*display: none;*/
}

JavaScript

var $input = $('.i1');

setTimeout(function() {
    var txt = '';

    //if (txt = window.getSelection) {
    //    txt = window.getSelection().toString();
    //} else {
    //    txt = document.selection.createRange().text;
    //}
    //console.log(txt);
    
//    if (txt) {
  //      var sel = window.getSelection();
        
        //$input2.val($input.val());
        
        set();
//    }
}, 4000);

function set() {
    
    //var rng = document.createRange();
    //rng.selectNode($input[0]);
    //var sel = window.getSelection();
    //sel.removeAllRanges();
        
    $input.appendTo('.hidden-bag');
    $input.focus();

    setTimeout(function() {
        $input.focus();
        //$input.appendTo('.normal');
        
        //$input.focus();
        //sel.addRange(rng);
    }, 1000);
    
}