ShoPo - How to copy a text to clipboard
SumantaWeb
Posted on January 31, 2022
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!")
}
💖 💪 🙅 🚩
SumantaWeb
Posted on January 31, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
tailwindcss Implementing Dark Mode and Theme Switching using Tailwind v4 and Next.js
November 29, 2024