JSFiddle - React, Tailwind, and code Playground

by Fabian Allel

HTML

<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<input type="text" value="ejemplo" id="ejemploInput">
<button id="boton">Copiar portapapeles</button>

JavaScript

$( document ).ready(function() {
	$('#boton').click(function(){
  	copiarPortaPapeles($('#ejemploInput').val());
  });


function copiarPortaPapeles(text){
  var textField = document.createElement('textarea');
  $(textField).text(text);
  document.body.appendChild(textField);
  $(textField).select();
  var compatible = document.execCommand('copy');
  $(textField).remove();
  if(!compatible){
  	alert('Este navegador no soporta esta funcionalidad, debes copiarlo manualmente');
  }
}



});