+ 5
Your Mom did you remove the line which selects the text
document.getElementById("cop").select();
This one you have to remove it
+ 2
You should write document.execCommand
+ 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.
+ 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.
+ 1
Did you select it before pressing button
+ 1
It is working for me
+ 1
Your Mom
You need to select text before copying
function my() {
var ele = document.getElementById('cop');
ele.select();
document.execCommand("copy");
}
0
function my(){
document.execCommand("copy")
}
0
I am using in mobile
0
I am on mobile and its working.