ateElement('textarea') document.body.appendChild(ta) ta.style.position = 'absolute' ta.style.top = '0px' ta.style.left = '0px' ta.value = code ta.select() ta.focus() var result = document.execCommand('copy') document.body.removeChild(ta) if(result)$(this).text('Copied') else $(this).text('Copy failed') $(this).blur() })).on('mouseleave', function (e) { var $b = $(this).find('.copy-btn') setTimeout(function () { $b.text('Copy') }, 300) }).append(e) })