To copy an email address to the clipboard when a button is clicked in JavaScript, you can use the following code:
index.tsx514 chars16 lines
This code creates a temporary input element, sets its value to the email address, appends it to the document body, selects its contents, and executes the copy command. Finally, it removes the temporary input element from the document body.
Make sure to replace "example@example.com"
with the actual email address you want to copy, and replace "copyButton"
with the id attribute of your button element.
Note: Due to browser security restrictions, the copy command may not work if it is not triggered by a user action, such as a button click.
gistlibby LogSnag