+ 5
Your Mom did you remove the line which selects the text document.getElementById("cop").select(); This one you have to remove it
17th May 2022, 1:24 PM
YUGRAJ
+ 2
You should write document.execCommand
17th May 2022, 1:30 AM
YUGRAJ
+ 2
function my(){ document.getElementById("cop").select(); document.execCommand("copy") } execCommand('copy') copies the selection to the clipboard, the selection is made using the select() method.
17th May 2022, 1:32 AM
Solo
Solo - avatar
+ 2
Your Mom execCommand is a function of global object document not an object of element that's why you get error. when you do document.getElementById('cop'). execCommand ('copy') it just copy once means when you try to edit textbox then do copy then it won't copy edited text. It just show you previous copied text.
17th May 2022, 4:58 AM
A͢J
A͢J - avatar
+ 1
Did you select it before pressing button
17th May 2022, 1:28 PM
YUGRAJ
+ 1
It is working for me
17th May 2022, 1:29 PM
YUGRAJ
+ 1
Your Mom You need to select text before copying function my() { var ele = document.getElementById('cop'); ele.select(); document.execCommand("copy"); }
17th May 2022, 1:45 PM
A͢J
A͢J - avatar
0
function my(){ document.execCommand("copy") }
17th May 2022, 1:08 PM
Solo
Solo - avatar
0
I am using in mobile
17th May 2022, 1:29 PM
YUGRAJ
0
I am on mobile and its working.
18th May 2022, 10:23 PM
Gazloco
Gazloco - avatar