Try using this line instead:
w.document.write('<div id="diary">' + $('#diary').html() + '</div>');
You are writing the internal html of your div, not the div tag.
The method above also writes the div tag with the correct id. I just pinned the identifier because you could format the div#diary and not the div .
EDIT
This method should keep the style.
function PrintContent() { var e = document.createElement('div'); e.id = 'diary'; e.innerHTML = $('#diary').html(); document.getElementById('t').appendChild(e); }
You just need to make space so that this content can be inserted, for example a div with id t . As in the example that I posted in the comments.
source share