I have json data in pre
tag
Below is the JS I have used
No errors in browser console. But when I paste the content in the pre
tag doesn't get pasted
var emailLink = document.querySelector('#filecontent1');
var range = document.createRange();
range.selectNode(emailLink);
window.getSelection().addRange(range);
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copy email command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
window.getSelection().removeAllRanges();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<pre id="filecontent1">
{
"a":"string a",
"b":"string b"
}
</pre>