If you want to click a button and have the contents of a div copied to the cut and paste clipboard, then this code will solve that problem.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<input type="button" id="copyme" value="COPY THE DIV"> <div id="mypolicy">THIS IS WHAT I WANT TO COPY</div> <script> $(document).on('click', '#copyme', function() { var range = document.createRange(); range.selectNode(document.getElementById("mypolicy")); window.getSelection().removeAllRanges(); // clear current selection window.getSelection().addRange(range); // to select text document.execCommand("copy"); window.getSelection().removeAllRanges();// to deselect }); </script> |