function contentCopy(input,title){ var r = document.createRange(); r.selectNode(document.getElementById(input)); window.getSelection().removeAllRanges(); window.getSelection().addRange(r); document.execCommand('copy'); window.getSelection().removeAllRanges(); toastr['success']( '@lang("Copied to clipboard!")',title); // optional bonus } $(document.body).on('click', '.js-copy-shortcut', function() { contentCopy($(this).data('id'), $(this).data('value')); });