I'm trying to copy the text from the next div to the clipboard with Javascript
. Below is my current code:
HTML:
<div class=hl7MsgBox>
<span class=boxspan>1</span>
<br>
<span class=boxspan>2</span>
<br>
<span class=boxspan>3</span>
<br>
<span class=boxspan>4</span>
<br>
<span class=boxspan>5</span>
<br>
<span class=boxspan>6</span>
<br>
<span class=boxspan>7</span>
<br>
<span class=boxspan>8</span>
</div>
Javascript:
$(.btnFileCopy).click(function () {
var copyText = document.getElementsByClassName(hl7MsgBox);
copyText.select();
document.execCommand(copy);
});
I'm expecting to get the new output when I paste it into the notepad
:
1
2
3
4
5
6
7
8
However, for some reason, it's not working and throw the next error message :
Uncaught TypeError: copyText.select is not a function ...
Does anyone know how could I solve this issue?