Created
April 2, 2016 04:30
-
-
Save mahedi2014/01051c37571ac1a7ccdc63f2a09aae36 to your computer and use it in GitHub Desktop.
js print a div html
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <script> | |
| function printContent(el){ | |
| var restorepage = document.body.innerHTML; | |
| var printcontent = document.getElementById(el).innerHTML; | |
| document.body.innerHTML = printcontent; | |
| window.print(); | |
| document.body.innerHTML = restorepage; | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <h1>My page</h1> | |
| <div id="div1">DIV 1 content...</div> | |
| <button onclick="printContent('div1')">Print Content</button> | |
| <div id="div2">DIV 2 content...</div> | |
| <button onclick="printContent('div2')">Print Content</button> | |
| <p id="p1">Paragraph 1 content...</p> | |
| <button onclick="printContent('p1')">Print Content</button> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment