(function() {
    // a stupidly simple copy button
    // - copies on awesome browsers/devices
    // - selects text on underwhelming mobile devices
    var copyBtn = document.querySelector('.js-copy-btn');
    copyBtn.addEventListener('click', function (event) {
        // select the text
        var copyItem = document.querySelector('.text-to-copy');
        var range = document.createRange();
        range.selectNode(copyItem);
        window.getSelection().addRange(range);
        try {
            // now that we've selected the text, execute the copy command
            var successful = document.execCommand('copy');
            if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
                document.getElementsByClassName('js-copy-btn')[0].textContent = "Now click 'Copy'";
            } else {
                document.getElementsByClassName('js-copy-btn')[0].textContent = "Copied!";
            }
        } catch (err) {
            document.getElementsByClassName('js-copy-btn')[0].textContent = "Epic fail!";
        }
        var selection = window.getSelection();
        range.selectNodeContents(copyItem);
        selection.removeAllRanges();
        selection.addRange(range);
        copyItem.focus();
        copyItem.setSelectionRange(0, 9999);
    });
});

(function() {
    // a stupidly simple copy button
    // - copies on awesome browsers/devices
    // - selects text on underwhelming mobile devices
    var copyBtn = document.querySelector('.js-copy-btn');
    copyBtn.addEventListener('click', function (event) {
        // select the text
        var copyItem = document.querySelector('.text-to-copy');
        var range = document.createRange();
        range.selectNode(copyItem);
        window.getSelection().addRange(range);
        try {
            // now that we've selected the text, execute the copy command
            var successful = document.execCommand('copy');
            if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
                copyBtn.textContent = "Now click 'Copy'";
            } else {
                copyBtn.textContent = "Copied!";
            }
        } catch (err) {
            copyBtn.textContent = "Epic fail!";
        }
        var selection = window.getSelection();
        range.selectNodeContents(copyItem);
        selection.removeAllRanges();
        selection.addRange(range);
        copyItem.focus();
        copyItem.setSelectionRange(0, 9999);
    });
});

use copyBtn var