Copy To Clipboard
Utility
JS
- Give the element attribute name and value of data-copy="Your text to copy"
- On click of the element, the attribute value will be copied to clipboard
<script>
document.addEventListener("DOMContentLoaded", function () {
document.addEventListener("click", (e) => {
const el = e.target.closest("[data-copy]");
if (!el) return;
navigator.clipboard.writeText(el.getAttribute("data-copy") || "");
});
});
</script>Preview Links
Custom JS
Enable custom code in preview or view on published site.
Enable custom code?
Last Updated: Dec 4, 2025
- Give the element attribute name and value of data-copy="Your text to copy"
- On click of the element, the attribute value will be copied to clipboard
<script>
document.addEventListener("DOMContentLoaded", function () {
document.addEventListener("click", (e) => {
const el = e.target.closest("[data-copy]");
if (!el) return;
navigator.clipboard.writeText(el.getAttribute("data-copy") || "");
});
});
</script>