I want to do
$('#foo').insertAfter('#bar');
but only when the user prints the page. I don't want to do any scripting while on screen.
I realize this would have been simple if I wanted to manipulate styles, because then I would have just used @media print {}
in CSS. However the goal I am trying to achieve (DOM manipulation) cannot be achieved with CSS, hence I need to use JS.
How can I run JavaScript (or jQuery) only when the user prints or does print-preview?