Put innerHTML into clipboard

I found the need to make it easier to copy something into the clipboard so I wrote this little Javacscript function based off of what I found in a web search.

function copyFunc(idToCopy) {
  /* Get the HTML Element based on ID passed to function */
  var copyText = document.getElementById( idToCopy );

  /* Select the inner HTML */
  copyData = copyText.innerHTML;

   /* Write the text to the clipbaod */

  /* Alert the copied text, uncomment if you want the alert */
  // alert("Copied the text: " + copyData);



Posted on

December 23, 2021

Submit a Comment

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