Created
May 10, 2018 18:08
-
-
Save wad3g/9b5fbcf77675719b674ca45e72ba6285 to your computer and use it in GitHub Desktop.
Target specific div / element to print
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
function printDiv(divName){ | |
var printContents = document.getElementById(divName).innerHTML; | |
document.body.innerHTML = printContents; | |
window.print(); | |
document.body.innerHTML = originalContents; | |
} | |
</script> | |
<h1>This Won't Print</h1> | |
<button onclick="printDiv('1')">Print #1</button> | |
<button onclick="printDiv('2')">Print #2</button> | |
<button onclick="printDiv('3')">Print #3</button> | |
<button onclick="printDiv('4')">Print #4</button> | |
<div id="1">Only print #1</div> | |
<div id="2">Only print #2</div> | |
<div id="3">Only print #3</div> | |
<div id="4">Only print #4</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment