DEV Community

Discussion on: Print a div tag content with Javascript.

Collapse
 
linehammer profile image
linehammer

var mywindow = window.open();
var content = document.getElementById(elem).innerHTML;
mywindow.document.write(content);
mywindow.print();

In the above code, when you click the button "Print a Div" , a JavaScript popup window is created and extracted the contents of the HTML div elements to store it in a JavaScript variable. Then the contents of the HTML div elements are written to the popup window and finally the window is printed using the JavaScript Window print() command.

net-informations.com/js/progs/prin...