Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

202
Vistas
how to paste content of clipboard?

I want to copy/paste some content from one div to another
In the example below clicking on paste button expected result in target div is - <p>lorem ipsum</p>
but simply - nothing happens

$('.btncopy').on('click', function(){
    let a = $('.story').html().trim();
    navigator.clipboard.writeText(a);
  console.log(a);  // it works
});
$('.btnpaste').on('click', function(){
    let a = navigator.clipboard.readText();
  console.log(a);  // doesn't work
    $('.target').text(a); 
});
.story, .target{min-height:25px; background:orange;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class='btncopy'>COPY</button>
<button class='btnpAste'>PASTE</button>
<div class='story'><p>lorem ipsum</p></div>
<br>
<div class='target'></div>

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

readText() (just as writeText) returns a Promise, you need to await for it. So in your case it will be something like this:


navigator.clipboard.readText().then(function(a) {
  console.log(a);  // works
  $('.target').text(a); 
});

However if you try it in the SO snippet runner (or any other JS fiddler online) it will not work due to permission restrictions.

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda