Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!