how to print a Div content in javascript

By using this script we can print the content of a Div. It is working fine.
We have to call this script like this:


<button onclick="printContent(print_div_id)">Print</button>


<script>
 function printContent(el)
 {
 var restorepage = document.body.innerHTML;
 var printcontent = document.getElementById(el).innerHTML;
 document.body.innerHTML = printcontent;
 window.print();
 document.body.innerHTML = restorepage;
 }
 </script>

Leave a Comment