Skip to content

Instantly share code, notes, and snippets.

@LiveBacteria
Forked from andrewlimaza/example.html
Created January 22, 2019 23:06
Show Gist options
  • Save LiveBacteria/899de61d57add1e6eb8c3d92340a13a5 to your computer and use it in GitHub Desktop.
Save LiveBacteria/899de61d57add1e6eb8c3d92340a13a5 to your computer and use it in GitHub Desktop.

Revisions

  1. @andrewlimaza andrewlimaza created this gist Dec 19, 2016.
    20 changes: 20 additions & 0 deletions example.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    <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>
    <h1> do not print this </h1>

    <div id='printMe'>
    Print this only
    </div>

    <button onclick="printDiv('printMe')">Print only the above div</button>