px'; // Prevent page scroll ta.style.position = 'absolute'; ta.style.opacity = '0'; ta.readOnly = true; ta.value = code; document.body.appendChild(ta); ta.select(); ta.setSelectionRange(0, code.length); ta.readOnly = false; var result = document.execCommand('copy'); if (result) $(this).text('Copied'); else $(this).text('Copy failed'); ta.blur(); // For iOS $(this).blur(); })).on('mouseleave', function(e) { var $b = $(this).find('.copy-btn'); setTimeout(function() { $b.text('Copy'); }, 300); }).append(e); })