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.
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
- Add the custom Javascript code snippet to your closing body custom code settings.
- Review the HTML to understand the structure
- Add an element ID print-content to the div that you want to have printed
- 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>