ShoPo - How to copy a text to clipboard (using JS!)
ShoPo is a new posting session which is Short! (SHOrt POst).
Yeah! we can copy a text to clipboard at a click of a button!
so how to do it?
so do the following --
1)Add a click function to the button
using
JavaScript
way 1
<button onclick="function()">Copy!</button>
using
JavaScript
way 2
<button id="copyButton">Copy!</button>
<!--- Just add a onClick event in js --->
using
Alpine
<button @click="function()">Copy!</button>
2)Now code the function
function(){
navigator.clipboard.writeText("text goes here!")
}
Top comments (0)