Now initialize Clipboard by specifying selector to the Clipboard Object.First, download clipboard.js library and include in your page.This library does not use Flash to copy content and it doesn’t depend on any framework or libraries. The button has a new attribute data-clipboard-target which has id of copying element e.g – #txt_copy.Įntered content will be copied when button gets clicked. Įxample 2 – Copy input Text and add Event Handlers Įxample 1 – data-clipboard-text AttributeĪdd the data-clipboard-text attribute to an element that contains copying Text and initialize CopyToClipboard.
Download plugin from GitHub and include file.This library does not use Flash to copy content but requires jQuery plugin. This copies the selected text on your document.ĭocument.getElementById('txt_copy').select() Īccording to the article in Mozilla Developer Network (MDN) on Document.execCommand(). In JavaScript, you can use document.execCommand('copy') to copy content.