<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));
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter