$(document).on("click", "[data-behavior=clipboard]", function(e) { e.preventDefault(); // Copy the value of the link's `href` attribute var value = $(this).attr("href"); // Creates a temporary input field to copy from var copyToClipboard = function(value) { var $temp = $(""); $("body").append($temp); $temp.val(value).select(); document.execCommand("copy"); $temp.remove(); } // Perform the copying copyToClipboard(value); });