How do I copy the text inside a div to the clipboard? I have a div and need to add a link which will add the text to the clipboard. Is there a solution for this?
Even better approach without flash or any other requirements is clipboard.js. All you need to do is add data-clipboard-target="#toCopyElement"
on any button, initialize it new Clipboard('.btn');
and it will copy the content of DOM with id toCopyElement
to clipboard. This is a snippet that copy the text provided in your question via a link.
One limitation though is that it does not work on safari, but it works on all other browser including mobile browsers as it does not use flash
$(function(){
new Clipboard('.copy-text');
});
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s
copy Text