This question has already been answered:

There is a button and a field below it with automatically generated code. By clicking on this button or on the field, the code in the field should be copied to the clipboard. Information in the field should not be editable. How is such a block implemented, is it in the bootstrap (I could not find it myself, although it is used very often on the site itself)?

enter image description here

Reported as a duplicate by members aleksandr barakin , Bald , Alex , Denis , user194374 on Dec 15 '16 at 10:47 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    $(function() { $('input').click(function() { $('#code')[0].select(); document.execCommand('copy'); $('#code').append(' '); $('#code').val().slice(0, -1); }); }); 
     textarea {width:250px;height:80px;resize:none;} 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <textarea id="code" readonly>I love this code</textarea> <br> <input type="submit" value="Копировать">