Assuming all your styles are inline, you need to get the html of the element, not the text. Sort of:
function copyToClipboard(element) { var $temp = $("<input>"); $("body").append($temp); $temp.val($(element).html()).select();
Edit based on comments:
To copy formatting to something like the body of a Gmail message or Word document, you must actually select an element as a range. When you paste the html content into a text box, you are actually copying the raw text. You want to do something like this:
function copyToClipboard(element) {
source share