0
I have a code below in Javascript that picks up the td
that was clicked and copied to the clipboard, but it is not working. The error you see on the console is:
(test). select(); is not a Function
The alert(teste)
returns the number of id
right. What I need is to copy this id
for clipboard clipboard.
$("td").click(function(e){
var teste = e.target.id;
alert(teste);
(teste).select();
document.execCommand('copy');
alert('Texto copiado para a área de transferência');
});
To do this, you need to put the text in a textarea.
– Wictor Chaves
Create a small textarea and make it transparent with css
– Wictor Chaves
Change to
$(teste).select();
– Sorack
But even if I put a textarea it returns the error (test). select(); is not a Function
– matheus
I left it : <td><textarea id="2">test</textarea></td>
– matheus
And my jquery looked like this:$("td textarea"). click(Function(e){ var test = $(this). text(); Alert(test); $(test). select(); Document.execCommand('copy'); Alert('Copied text; });
– matheus
would not be
teste.select();
??– hugocsl
test.select() Error: .teste.select() is not a Function...
– matheus
var test = $(this). text(); Alert(test); (this). select(); Document.execCommand('copy');
– matheus
I believe you need to copy the element itself and not the value. Do as colleagues have said, copy the TD text to the textarea and do the "var test = $('#2')", your text being and see if it works.
– Leonardo Buta