Print button that prints only what’s within a div tag

Do you want to have a button on a webpage that allows the user to print only a portion of the content on the webpage?   One approach is to setup your webpage so that the “print” button will only print the content that you put within a ”

” tag.
NOTE:   another approach to printing only part of a webpage is shown here:
Step 1 – Put this Javascript in your webpage:
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
document.body.innerHTML = originalContents;
Step 2 – Put a div tag around part of your webpage with an ID:
 content you want to print here….
Step 3 – Put a button inside your div tag so a user can print the div tag
<input type='button' value='Print This Only' onclick="printDiv('example');"/>"

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s