skylight_animation

Copy Text to Clipboard | Element HTML

Feb 5th, 2021
9,499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.46 KB | None | 0 0
  1. <link rel="stylesheet" type="text/css" href="https://skylightanimation.github.io/assets/plugin/font-awesome/4.7.0/css/font-awesome.css">
  2. <link rel="stylesheet" type="text/css" href="https://skylightanimation.github.io/assets/plugin/bootstrap/3.3.7/bootstrap.min.css">
  3. <script type="text/javascript" src="https://skylightanimation.github.io/assets/plugin/jquery/jquery-3.4.1.min.js"></script>
  4. <script type="text/javascript" src="https://skylightanimation.github.io/assets/plugin/bootstrap/3.3.7/bootstrap.min.js"></script>
  5.  
  6. <div class="container">
  7.     <br>
  8.     <div class="thumbnail text-box">
  9.         <div id="text-copy">
  10.             Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
  11.             quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
  12.         </div>
  13.         <button class="btn btn-xs btn-copy btn-primary">
  14.             <span class="fa fa-copy"></span> Copy
  15.         </button>
  16.     </div>
  17. </div>
  18.  
  19. <style type="text/css">
  20.     .btn-copy{
  21.         position: absolute;
  22.         top: 0;
  23.         right: 0;
  24.         margin: 5px 10px;
  25.     }
  26.     .text-box{
  27.         position: relative;
  28.     }
  29. </style>
  30.  
  31. <script type="text/javascript">
  32.     $(document).ready(function(){
  33.         $('.btn-copy').on("click", function(){
  34.             var value = $('#text-copy').text();
  35.            
  36.             var $tempCopy = $("<input>");
  37.                 $("body").append($tempCopy);
  38.                 $tempCopy.val(value).select();
  39.                 document.execCommand("copy");
  40.                 $tempCopy.remove();
  41.         })
  42.     })
  43. </script>
Advertisement
Add Comment
Please, Sign In to add comment