JSFiddle - React, Tailwind, and code Playground
HTML
<button id="btn">hello</button>
<button id="btn2"> Z҉A҉L҉G҉O̚̕̚!</button>
CSS
let clipboard = new myClipboard()
Z҉A҉L҉G҉O̚̕̚
Z҉A҉L҉G҉O̚̕̚hello world Z҉A҉L҉G҉O̚̕̚ Z҉A҉L҉G҉O̚̕̚hello world
JavaScript
let clipboard = new myClipboard()
btn.onclick = ()=>{
clipboard.push('hello world')
}
btn2.onclick = ()=>{
clipboard.push(' Z҉A҉L҉G҉O̚̕̚')
}
function myClipboard() {
var self = this
this.init = ()=>{
this.el = document.createElement('textarea')
this.el.style = "position: absolute; left: -999px; bottom: 0; width: 300px;";
document.body.appendChild(this.el)
return self
}
this.push = text=>{
this.el.textContent = text
this.el.select()
document.execCommand('copy')
}
if (!this.el) this.init()
return this
}