Forum Moderators: not2easy
@media screen {
#printSection {
display: none;
}
}
@media print {
body * {
visibility:hidden;
}
#printSection, #printSection * {
visibility:visible;
}
#printSection {
position:absolute;
left:0;
right:0;
top:0;
}
}
<div id="printable">
<div class="modal-header">
<h1>Printable</h1>
</div>
<div class="modal-body">
print content here
</div>
</div> document.getElementById("btnPrint").onclick = function () {
printElement(document.getElementById("printable"));
}
function printElement(elem) {
var domClone = elem.cloneNode(true);
var $printSection = document.getElementById("printSection");
if (!$printSection) {
var $printSection = document.createElement("div");
$printSection.id = "printSection";
document.body.appendChild($printSection);
}
$printSection.innerHTML = "";
$printSection.appendChild(domClone);
window.print();
}
body * {
visibility:hidden;
} Descendant elements do not generate any boxes either; the element and its content are removed from the formatting structure entirely. This behavior cannot be overridden by setting the 'display' property on the descendants.
when I print it a non-modal pages