Simple way to create copy text Button using Java Script

In our website sometimes we need a button to which can copy the specific text like HTML code or something. This is very easy by Java Script

Here is the HTML code:

<div class="col-md-6">
 <h3>Simple way to create copy text Button using Java Script</h3>
 <textarea id="textarea1" class="form-control" style="height: 140px; background: #efefef">
 Click on the button to copy the text from the text field. Try to paste the text (e.g. ctrl+v) afterwards in a different window, to see the effect.
We believe that coder always want to know the simple way to code. That's why we trying to coding something like different. Website or Application whatever we do we should smarter, update and be impassioned.
</textarea>
<button onclick="copyFunction()" class="btn btn-primary" onmouseout="outFunc()">
 <span class="tooltiptext" id="myTooltip">copy code </span>
 </button>
 </div


Here is the Java Script code:
 <script>
            function copyFunction() {
                var copyText = document.getElementById("textarea1");
                copyText.select();
                document.execCommand("copy code");
                var tooltip = document.getElementById("myTooltip");
                tooltip.innerHTML = "Copied...";
            }
        </script>


No comments

Powered by Blogger.