I have this simple function that allows you to click any table cell and it copies the data to the clipboard. The cell will also blink red to let you know it was copied. This works fine, but you'll notice there's an input tag in each cell (all the similar examples I found also used inputs or some other form tags) I don't need inputs because the data in my cells isn't going to change. Is there a way to do this without input tags. Would the data in a normal table cell be innerHTML Can that be copied onclick? No jQuery please.
function myFunction(itemid) {
var copyText = document.getElementById(itemid);
copyText.select();
document.execCommand("Copy");
// blink red
document.getElementById(itemid).style.backgroundColor="#FF0000";
setTimeout(function(){document.getElementById(itemid).style.backgroundColor="#FFFFFF";},300);
}
::selection {background:none;}
input {outline:0;cursor:pointer}
<table>
<td><input type="text" value="Cheese" id="cell1" onclick="myFunction('cell1')"></td>
<td><input type="text" value="Crackers" id="cell2" onclick="myFunction('cell2')"></td><tr>
<td><input type="text" value="Milk" id="cell3" onclick="myFunction('cell3')"></td>
<td><input type="text" value="Bread" id="cell4" onclick="myFunction('cell4')"></td>
</table>