Valentin BEAULE Valentin BEAULE - 10 months ago 81
jQuery Question

Select the value of a TD on click to ease copy

I want to select onclick the innerHTML of a td so the user can just do ctrl+C to copy the content.

I tried many combination and I can't find a way. However it seams to work on inputs with a simple


Adding a focus don't effect anything, and the .select() send and error:

document.getElementById(...).select is not a function

So how can I do with a td element?
I don't mind if it's not working on IE.


You can select text of td when it clicked.

    var range = document.createRange();
    var sel = window.getSelection(); 
table, tr, td {
    border: 1px solid black;
<script src=""></script>