click to copy text

PHOTO EMBED

Fri Apr 04 2025 12:40:39 GMT+0000 (Coordinated Universal Time)

Saved by @divyasoni23 #css #html

<div class="coupon--card-content">
<h2>Limited Time Offer Flat 20% Off!</h2>														<p>Get 20% off on your first order of medicines. Shop now and save on your healthcare essentials!</p>
<h3>FLAT20</h3>
<a href="javascript:void(0)" data-coupon="FLAT20" class="copy-text">
Use Coupon</a></div>

import $, { contains } from 'jquery';

class Coupon {
	constructor(element) {
		this.$element = $(element);
		this.$copy = $(element).find('.copy-text');
		this.init();
	}

	init() {
		this.$copy.on('click', function (e) {
			e.preventDefault();
			let target = $(this).data('coupon');
			navigator.clipboard.writeText(target).then(() => {
				console.log(`Copied: ${target}`);
			});
		});
	}
}

$('[data-coupon]').each((index, element) => new Coupon(element));
content_copyCOPY