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:

HTML:

JS:

<script>
 jQuery(".copyButton2").click(function () {
            jQuery(this).text(function(i, v){
               return v === 'Copy' ? 'Copied!' : 'Copy'
            })
        });
</script>

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


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: