Copy Text From Specific Selector [Jquery]

var msgLog = $('.message_log');
msgLog.hide();

$(`.selectorBtn`).click(function (e) {
            e.preventDefault();
            var copyText = $('.selector').attr('get_attribute');

            document.addEventListener('copy', function (e) {
                e.clipboardData.setData('text/plain', copyText);
                e.preventDefault();
            }, true);

            document.execCommand('copy');
            msgLog.text('Short link copied!');
            msgLog.show();
            setTimeout(()=>{
                msgLog.hide();
            }, 3000);
        })

Leave a comment