- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set the page-break behavior before an element with JavaScript?
Use the pageBreakBefore property in JavaScript to set the page-break behavior before an element. Use the always property to insert a page break before an element.
Note − The changes would be visible while printing or viewing the print preview.
Example
You can try to run the following code to return the page-break behavior before an element with JavaScript −
<!DOCTYPE html> <html> <body> <h1>Heading 1</h1> <p>This is demo text.</p> <p>This is demo text.</p> <p id = "myFooter">This if footer text.</p> <button type="button" onclick = "display()">Set page-break</button> <script> function display() { document.getElementById("myFooter").style.pageBreakBefore = "always"; } </script> </body> </html>
Advertisements