Skip to content

Instantly share code, notes, and snippets.

@narwanimonish
Created December 12, 2019 10:47
Show Gist options
  • Save narwanimonish/66fc83e6643a82e980f39ff93a21b5b3 to your computer and use it in GitHub Desktop.
Save narwanimonish/66fc83e6643a82e980f39ff93a21b5b3 to your computer and use it in GitHub Desktop.
How to print single elment (div) of tab in any browser in javascript
function PrintElem(elem)
{
var mywindow = window.open('', 'PRINT', 'height=400,width=600');
mywindow.document.write('<html><head><title>' + document.title + '</title>');
mywindow.document.write('</head><body >');
mywindow.document.write('<h1>' + document.title + '</h1>');
mywindow.document.write(document.getElementById(elem).innerHTML);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/
mywindow.print();
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment