Replace button text onclick JS

I’m trying to change button text on button click so that the text changes from ‘Copy’ to ‘Copied!’ as part of a custom clipboard setup. Here is the code I’m using:



 jQuery(".copyButton2").click(function () {
            jQuery(this).text(function(i, v){
               return v === 'Copy' ? 'Copied!' : 'Copy'

which doesn’t appear to be working correctly.

I have also tried modifying this solution to no avail. Is there an obvious reason why this isn’t working?

Read more here: Replace button text onclick JS

Leave a Reply

Your email address will not be published. Required fields are marked *