Copy button feature problem

Copy button feature problem
0.0 0

#1

for the project Random quote generator I’m trying to add Copy button for copying the quote but seems doesn’t work
here is my codepen : https://codepen.io/HamedOKhaled/pen/ELygwL


#2

Hello,

Are you still having issues with this?

Could you explain what your Copy button is supposed to do? What do you mean by “copying the quote”.

Lex


#3

Hey @kittyfantastico !
Yes unfortunately it still not work and I removed it from the codepen
what I wanted to do is when pressing the button Copy quote it’s copied to the clipboard so I can paste it in my facebook for example!,


#4

You can not copy to clipboard from elements like div, p, or span. However, you can from elements like input and textarea, because they have the value property. What you can do is create a textarea element (give it an id of hidden-text). In your JavaScript, after you change the text for div with id=“txt”, add the following line to change the value of the textarea:

$("#hidden-text").val(json.quote);

Then all you have to do is target the textarea with id=“hidden-text” in the callback function for the button with id=“cpy” instead of targeting the div with id=“txt”.