// Get the element
var elem = document.querySelector('#elem1');
// Create a copy of it
// The 'true' is to allow nested elements to be copied as well
var clone = elem.cloneNode(true);
function CopyToClipboard(containerid) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().removeAllRanges(range);
window.getSelection().addRange(range);
document.execCommand("copy");
alert("Text Copied to clipboard");
}