Skip to content

Instantly share code, notes, and snippets.

@MarkMYoung
Created December 29, 2020 22:29
Show Gist options
  • Save MarkMYoung/4b215514cc5c324c18c78ff45c68fee5 to your computer and use it in GitHub Desktop.
Save MarkMYoung/4b215514cc5c324c18c78ff45c68fee5 to your computer and use it in GitHub Desktop.
Print a target `div` of a web page.
function printDiv( divId )
{
let divContents = document.getElementById( divId ).innerHTML;
let printWindow = window.open( '', '', 'height=200,width=400' );
printWindow.document.write( '<html><head><title>Print DIV Content</title></head><body>' );
printWindow.document.write( divContents );
printWindow.document.write( '</body></html>' );
printWindow.document.close();
printWindow.print();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment