Print A Specific Part using Javascript

By using the below code you can print the specific portion of the web using id or class. Just use the below code of javascript to print the portion of a web page.

Use the below code in your HTML file:

<div style="padding-top:30px;">
<button type="button"   onclick='printDiv();' class="btn btn-primary" >Print</button>
<div id="printdiv" >
I am here , Please print me.
<div id="printdivnot" >
Please don't print me.

Below is the javascript Code :

function printDiv() {

var divToPrint = document.getElementById('printdiv');

var newWin ='', 'Print-Window');;

newWin.document.write('<html>' +
'<body onload="window.print()">' + divToPrint.innerHTML + '</body>'+


setTimeout(function () { newWin.close(); }, 10);


You can see demo below :


Read More
Show a particular div on Dropdown item Selection Below is the code snippet used to show different Data on the change of dropdown items. You can use the code below and customize it according to you...
Get Query String Value with Jquery & Javascri... Use Below code to get the Query string value from URL using Jquery & Javascript. For example, if someone hits below URL you will get Id value f...
Auto Post Form Data With Ajax at Specific Interval... Below code is used to post form data using Ajax on a specific interval (i.e. 10 seconds). Customize the code as you like and use it in your project. ...
Auto Save A form Data Using Javascript You can use the below code snippet for auto saving the form data using JavaScript on a specific interval. var myInterval = setInterval(function (...
Related :  Auto Post Form Data With Ajax at Specific Intervals

Posted by Editorial Staff

We are official editorial team of consult machine. We write articals about ASP MVC, SQL Server , C# And Jquery.