2

is it possible to not print a div include in a printThis() element ?

example :

<div id="print-it">

<div>hello</div>

<div id="no-print-this">
<button>must be show on page but not print</button>
</div>

</div>

<button id="printMe">Print button</button>

AND JQUERY

$("#printMe").click(function () {
$('#print-it').printThis();
});
});

the div id "no-print-this" is ever show to print... is it possible to hide it on the print page with this jQuery printing plugin method ?

Can add $('#no-print-this').hide(); to the jquery click function but div "no-print-this" is not show again after closing print window browser...

The @media print method have no effect here. So i dont know if its possible with the prinThis jquery plugin.

Thanks !

nickko
  • 356
  • 3
  • 12
  • Possible duplicate of [How do I hide an element when printing a web page?](https://stackoverflow.com/questions/355313/how-do-i-hide-an-element-when-printing-a-web-page) – showdev Nov 08 '18 at 18:06
  • humm no :) @media print use css only and PrinThis() jquery – nickko Nov 08 '18 at 20:11
  • `@media print` is a CSS media query to manipulate elements when printing. You'll still use JavaScript to do the actual printing. You might use the [`importCSS`](https://github.com/jasonday/printThis#importcss) or [`loadCSS`](https://github.com/jasonday/printThis#loadcss) options of `printThis()` to load the media query CSS. See [Styling Printed Content](https://github.com/jasonday/printThis/wiki/Styling-Printed-Content) for `printThis()`. – showdev Nov 08 '18 at 20:15
  • Many thanks Showdev ! you true. i'll post the solution with your tips (loadCSS). its ok :)) – nickko Nov 08 '18 at 20:42
  • 1
    I am the printThis author and and @showdev is correct - using `@media print` is the preferred method to exclude elements. Additionally, you may want flesh out the `@media print` to ensure a good experience for users that use `control + p` bypassing printThis – Jason Nov 10 '18 at 02:22
  • Thanks @jason for this information and you're very useful plugin :) clap clap :) – nickko Nov 10 '18 at 14:17
  • @nickko you can also add the `@media print` to your base CSS and you won't need `loadCSS` for exclusively print media (unless you are making printThis specifix changes beyond `control + p` – Jason Nov 11 '18 at 15:58

1 Answers1

6

so the solution : (thanks to Showdev)

$("#printMe").click(function () {

$('#print-it').printThis({
            importCSS: true,
            importStyle: true,
            loadCSS: "/assets/css/print_rules_page1.css"
            });
});

it need to use inportCSS and loadCSS with the printThis() jquery plugin

CSS ("loadCSS" load file print_rules_page1.css)

@media print 
{
#no-print-this,#no-print-this2 *{
display: none !important;
}
}
nickko
  • 356
  • 3
  • 12