-1
Good night.
I’m trying to create a script that copies the text of <td>
by clicking on it. Since the complete table has more than 2000 lines I am trying not to put commands directly into <td>
and not to impair the performance of the page.
Example: when I click on the cell "Alpha", the contents of the cell will be copied to the clipboard, i.e."Alpha".
I couldn’t find an answer to any similar situation, either on Stack or other sites. Does anyone have any idea how this script could be mounted.
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
<h2>AÇÕES</h2>
<table>
<tbody>
<tr><th>Ação</th><th>Descrição</th><th>Destino</th></tr>
<tr><td>0906</td><td>Comando A</td><td>Alfa</td></tr>
<tr><td>0047</td><td>Comando B</td><td>Beta</td></tr>
<tr><td>0796</td><td>Comando C</td><td>Gama</td></tr>
</tbody>
</table>
Thank you very much for your reply, Jhonny Freire, you
– Lucas
Lucas, if it worked, mark it as a valid answer so that other people can benefit when they have the same problem.
– Jhonny Freire
Jhonny Freire, would you know how I can copy in a single click, both the cell
<td>
which has been clicked, for example, on the subsequent cell? Currently I am modifying the text to be copied like this: clip.writeText('complement for' + tr.innerHTML + 'extractor')– Lucas
It’s basically the same thing, but you need to understand the code I posted here, if you understand will be able to do it quietly, just go through the 'tds' as was done in the 'tr' here in the code and get the next element using i+1. But for that you need to have understood the code I posted, you understood what and how it does?
– Jhonny Freire