Reputation: 98
Trying to select what will be printed on window.print()
.
Added the outmost element, so it contains childs elements (what explains the reason of using .printable
and .printable *
), class with printable
, and added the style:
@media print{
*:not(.printable *, .printable){
display: none !important;
}
}
The window.print()
, when called, still shows everything.
EDIT 1
Tried to add notPrintable
to all :not(.printable, .printable *, .notPrintable)
with jQuery and refer notPrintable
on @media print
.
Code:
jQuery:
$(":not(.printable, .printable *, .notPrintable)").addClass("notPrintable");
CSS:
@media print{
.notPrintable{
display: none !important;
}
}
Now nothing shows.
EDIT 2
Putting the solution example here if anyone needs it (available only after having an answer marked as accepted):
Upvotes: 1
Views: 227
Reputation: 98
$("body *:not(.printable, .printable *, .notPrintable)").addClass("notPrintable");
and
@media print{
.notPrintable {
display: none !important;
}
}
did the trick.
The "selector" tip was given by @westdabestdb
Upvotes: 0
Reputation: 4648
You can hide all elements and override the specific class in print media query.
@media print{
body *:not(.printable) {
display: none;
}
}
Upvotes: 1