Copy-to-clipboard helper function Example

Copy-to-clipboard helper function

Back to Tutorial


This is just a little helper function to add a 'click' event listener to a DOM element that will copy any defined text to the user's clipboard. It also allows for a callback function, presumably to present the user with some sort of indication that the text was actually copied to their clipboard.

//usage example
createCopy('Sample text to copy', 'elementId', function () {
alert('A callback function to show your text was copied successfully!');