$('.copy_button').on( 'click', function(e){ e.preventDefault(); copyToClipboard( $(this).attr('href') ); }); function copyToClipboard(element) { var $temp = $("<input>"); $("body").append($temp); $temp.val(element).select(); document.execCommand("copy"); $temp.remove(); }