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 "<div>" tag.

NOTE: another approach to printing only part of a webpage is shown here:

Print only a portion of a web page

Step 1 - Put this Javascript in your webpage:

<script>

function printDiv(divName) {

var printContents = document.getElementById(divName).innerHTML;

var originalContents = document.body.innerHTML;

document.body.innerHTML = printContents;

window.print();

document.body.innerHTML = originalContents;

}

</script>

Step 2 - Put a div tag around part of your webpage with an ID:

<div id=example>

content you want to print here....

</div>

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);'/>"