Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
change button text after click w/ clipboard.js

I'm using clipboard.js to copy some text on my webpage. I've go that working great but I'd like to change the button text after a user clicks to copy the text.

Here's what I have so far: a div with the text:

<div #landingpage>
TEST TEXT
</div>

a button:

<button class="btn" id="copy-button" data-clipboard-target="#landingpage" 
onclick="myFunction()">Copy Content</button>

and javascript:

<script>
(function(){
  new Clipboard('#copy-button');
})();
</script>

How do change button text to "Copied" after I click and then have it revert back to just "Copy" after a few seconds.

Thank you.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You could listen to the success event of the clipboard and change the text.

JS

$(function() {
  var $btnCopy = $('#copy-button');

  $btnCopy.on('click', function() {
    var clipboard = new Clipboard('#copy-button');

    clipboard.on('success', function(e) {
      $btnCopy.text('Copied');

      setTimeout(function() {
        $btnCopy.text('Copy');
      }, 2000);
    });
  });
});

HTML

<div id="landingpage"> TEST TEXT  </div>

<button class="btn" id="copy-button" data-clipboard-target="#landingpage">Copy Content</button>

Check Fiddle

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda