<script>
function copyClipboard() {
var elm = document.getElementById("divClipboard");
// for Internet Explorer
if(document.body.createTextRange) {
var range = document.body.createTextRange();
range.moveToElementText(elm);
range.select();
document.execCommand("Copy");
alert("Copied div content to clipboard");
}
else if(window.getSelection) {
// other browsers
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(elm);
selection.removeAllRanges();
selection.addRange(range);
document.execCommand("Copy");
alert("Copied div content to clipboard");
}
}
</script>
Plese modify this code so that it can be used for classes rather then for id. If I change "getElementById" to "getElementsByClassName" the code doesn't work. So please help .