I'm trying to add a small popup tooltip to the following code to show that text was successfully copied to the clipboard when the element is clicked. I would like the tooltip to popup saying "Copied" on a click or touch in the case of mobiles for a second, then disappear untill another item is copied.
The code is as follows:
const tds = document.querySelectorAll("td");
tds.forEach(td => {
td.onclick = function() {
document.execCommand("copy");
}
td.addEventListener("copy", function(event) {
event.preventDefault();
if (event.clipboardData) {
event.clipboardData.setData("text/plain", td.textContent);
console.log(event.clipboardData.getData("text"))
}
});
})
<table><tbody><tr><td>Data 1</td><td>Data 2</td><td>Data 3</td></tr></tbody></table>