I have the following function that copies text in a div to the clipboard. After 3 seconds I would like it to deselect the text. I can't get it to deselect the text in the div via the setTimeout. I have tried blur, trigger and click. Is there a solution?
function copyUsingJquery(element_id) {
$(element_id).attr("contenteditable", true)
.select()
.on("focus", function () {
document.execCommand('selectAll', false, null)
})
.focus();
document.execCommand("Copy");
$(element_id).removeAttr("contenteditable");
setTimeout(function () {
//deslect text on page after a few seconds
$(element_id).trigger("click");
}, 3000);
}