There are several ways to print the div or section, however I found this is easiest way and it works fine.
Code Sample
function printDiv(divID) {
var printContents = document.getElementById(divID).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}
Let me a bit explanation of the code. First we are selecting the contents of div as well as full body. Before print call, we are assigning the div contents to body and doing print. Finally, we are restoring the original body contents.
No comments:
Post a Comment