Javascript set print stylesheet
17,234
Solution 1
This question is a little vague, so I'm not sure if I'm following what you're trying to do. Are you trying to dynamically modify the style of an object for print?
If so, you can try adding styles to the head, like the following:
$('head').append('<style type="text/css" media="print">Whatever styles</style>');
Solution 2
You are going to need to add a CSSStyleSheet
to document.styleSheets
and set the media
type to print
. https://developer.mozilla.org/en/DOM/stylesheet
Author by
Leticia Meyer
Updated on June 04, 2022Comments
-
Leticia Meyer about 2 years
How would I modify the style of an object for the print stylesheet? I'm using jQuery, if that's of any help.
I basically want to set a css property of an object, but have that property apply for print only, not screen. e.g.
$('#myobject').css('background','white','print');