clickToCopy.js

var copyBtn = document.querySelector('.clicktoCopy'); copyBtn.addEventListener('click', function(event) { var emailLink = document.querySelector('.clicktoCopy'); var range = document.createRange(); range.selectNode(emailLink); window.getSelection().addRange(range); try { var successful = document.execCommand('copy'); var msg = successful ? 'successful' : 'unsuccessful'; console.log('Copy command was ' + msg); $(".copySuccess").fadeIn( 150 ).delay( 1500 ).fadeOut( 200 ); } catch(err) { console.log('Oops, unable to copy'); $(".copyError").fadeIn( 150 ).delay( 1500 ).fadeOut( 200 ); } window.getSelection().removeAllRanges(); });

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.