Code

Print Div with Button

Create a quick and easy printable div section for your Webflow site via this JS code snippet. This snippet allows you to designate which div will be printed when a user clicks on the print page button.

Print Div with Button preview

Create a quick and easy printable div section for your Webflow site via this JS code snippet. This snippet allows you to designate which div will be printed when a user clicks on the print page button.

How to add it

  1. Add the custom Javascript code snippet to your closing body custom code settings.
  2. Review the HTML to understand the structure
  3. Add an element ID print-content to the div that you want to have printed
  4. Add an element ID to the print button of print-btn

The code

Javascript
                      <!-- Add to closing body section -->
<script>
document.getElementById("print-btn").addEventListener("click", function() {
    var printContents = document.getElementById('print-content').innerHTML;
    var originalContents = document.body.innerHTML;
    document.body.innerHTML = printContents;
    window.print();
    document.body.innerHTML = originalContents;
});
</script>

                    

Browse similar code snippets

Language

More from Corey Moen

Profile →

Related Webflow questions

All answers →